Consider: int x = 10; int *p = &x; What does the expression *p represent?
Answer: C
The dereference operator (*) accesses the value at the address pointed to by p, which is the value 10.
Q.22Easy
Which operator is used to get the address of a variable?
Answer: B
The & (address-of) operator returns the memory address of a variable.
Q.23Easy
What will be printed by the code: char *ptr = "Hello"; printf("%c", *ptr);
Answer: A
ptr points to the first character of the string, so *ptr dereferences to 'H'. The %c format specifier prints a single character.
Q.24Medium
A void pointer can be used to store addresses of variables of any data type. However, it must be cast before dereferencing. Which statement about void pointers is FALSE?
Answer: B
A void pointer cannot be directly dereferenced. It must be cast to the appropriate pointer type first.
Q.25Medium
Consider the code: int arr[] = {5, 10, 15, 20}; int *ptr = arr; ptr++; What does ptr now point to?
Answer: C
Pointer arithmetic increments by the size of the data type. For int (4 bytes), ptr++ moves to the next integer, which is arr[1].
Advertisement
Q.26Medium
Which of the following best describes a dangling pointer situation?
Answer: B
A dangling pointer occurs when it points to memory that no longer exists, typically after free() or when a local variable goes out of scope.
Q.27Medium
Consider: int x = 5; int *p = &x; int q = &p; What is the value of q?
Answer: A
q is a pointer to pointer p. **q dereferences twice: first to get p, then to get the value x, which is 5.
Q.28Medium
Which memory allocation function does NOT initialize allocated memory to zero?
Answer: D
malloc() and realloc() return uninitialized memory with garbage values. calloc() initializes all bytes to zero.
Q.29Medium
Consider: int arr[5] = {1, 2, 3, 4, 5}; int *p = arr; What is the value of *(p+2)?
Answer: B
p points to arr[0]. p+2 points to arr[2], and *(p+2) dereferences to the value at arr[2], which is 3.
Q.30Medium
A function needs to modify a variable in the calling function. Which parameter passing method is appropriate?
Answer: B
To modify a variable in the calling function, you must pass its address (pointer). Pass by value creates a copy and cannot modify the original.
Q.31Medium
Consider: void func(int *arr, int size); This function prototype suggests that func will:
Answer: B
Since an array pointer is passed, the function can access and modify the original array elements in the caller's scope.
Q.32Medium
What will be the output of: int x = 10; int *p = &x; printf("%p", p); (assuming typical system output)
Answer: B
The %p format specifier prints the pointer value as a memory address in hexadecimal format, not the dereferenced value.
Q.33Hard
In a function that returns a pointer, which of the following is UNSAFE?
Answer: B
Returning a pointer to a local variable is unsafe because the variable ceases to exist after the function returns, creating a dangling pointer.
Q.34Hard
Consider: int *p = (int *)malloc(5 * sizeof(int)); for(int i=0; i<5; i++) *(p+i) = i*10; Which statement correctly deallocates this memory?
Answer: B
malloc() allocated memory must be freed using free(p), not free(&p). After freeing, it's good practice to set p = NULL.
Q.35Hard
A programmer uses a pointer variable but forgets to initialize it before dereferencing. Which type of error will occur?
Answer: C
Uninitialized pointers contain garbage values. Dereferencing them accesses arbitrary memory locations, causing runtime errors or undefined behavior.
Q.36Easy
What is the size of a pointer variable in a 64-bit system?
Answer: A
In a 64-bit system, all pointers occupy 8 bytes regardless of the data type they point to.
Q.37Easy
What does the & operator do when used with a variable?
Answer: B
The & (address-of) operator returns the memory address of the variable.
Q.38Easy
What is the output of the following code?
int x = 20;
int *p = &x;
printf("%d", *p);
Answer: B
The * operator dereferences the pointer p, accessing the value it points to, which is 20.
Q.39Easy
Which of the following is a void pointer?
Answer: B
void* is a generic pointer that can hold addresses of any data type and requires explicit typecasting when used.
Q.40Medium
What is the difference between pointer and array name in C?
Answer: B
Array names are pointer constants that point to the first element and cannot be reassigned, while pointer variables can be modified to point to different addresses.