Consider the following code:
char str[] = "HELLO";
int len = 0;
while(str[len] != '\0') {
len++;
}
printf("%d", len);
What will be the output?
Answer: A
The string "HELLO" has 5 characters. The while loop counts characters until it encounters the null terminator '\0'. The output will be 5. The null terminator is not counted in the length.
Q.482Easy
Which operator is used to get the address of a variable in C?
Answer: B
The & operator (address-of operator) returns the memory address of a variable.
Q.483Easy
What will be the size of a pointer variable on a 64-bit system?
Answer: C
On a 64-bit system, a pointer is 8 bytes (64 bits) regardless of the data type it points to.
Q.484Easy
What is a NULL pointer?
Answer: A
A NULL pointer is a pointer that points to memory address 0, indicating it doesn't point to any valid memory location.
Q.485Medium
What is the output?
int a = 5;
int *p = &a;
int q = &p;
printf("%d", q);
Answer: A
q is a pointer to pointer p. **q dereferences q to get p, then dereferences p to get the value 5.
Advertisement
Q.486Medium
What happens when you increment a pointer?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p++;
Answer: B
When a pointer is incremented, it moves to the next element based on the data type size (pointer arithmetic).
Q.487Easy
Which of the following is NOT a valid pointer declaration?
Answer: D
& is a reference operator used in C++, not in C. In C, pointers are declared using *.
Q.488Medium
What is the output?
int x = 10, y = 20;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
Answer: B
After p = q, pointer p now points to y. So *p gives the value of y, which is 20.
Q.489Easy
Identify the output:
char *str = "Hello";
printf("%c", *str);
Answer: A
*str dereferences the pointer to get the first character of the string, which is 'H'.
Q.490Hard
What is the difference between *p++ and (*p)++?
Answer: B
Due to operator precedence, *p++ is equivalent to *(p++), incrementing the pointer. (*p)++ explicitly increments the value.
Q.491Medium
What will be printed?
int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p+2));
Answer: C
p+2 points to the third element of the array. *(p+2) dereferences it to get 3.
Q.492Medium
What is a wild pointer?
Answer: B
A wild pointer is an uninitialized pointer that contains an arbitrary/garbage memory address.
Q.493Medium
What is the output?
int *p = NULL;
if(p) printf("Not NULL");
else printf("NULL");
Answer: B
NULL pointer evaluates to false in a conditional, so the else block executes.
Q.494Medium
Which of the following correctly allocates memory for 10 integers?
Answer: B
malloc requires the size in bytes. For 10 integers, we need 10 * sizeof(int) bytes.
Q.495Medium
What is a dangling pointer?
Answer: A
A dangling pointer is a pointer that points to memory that has been freed or deallocated.
Q.496Hard
What does the following code do?
int *p = (int*)malloc(sizeof(int));
*p = 5;
free(p);
p = NULL;
Answer: A
This is proper memory management: allocate, use, free, and nullify to prevent dangling pointer.
Q.497Medium
What will be the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", arr[1], *(p+1));
Answer: A
arr[1] and *(p+1) both access the second element of the array, which is 20.
Q.498Hard
Which statement is true about void pointers?
Answer: A
void pointers are generic pointers that must be cast to appropriate type before dereferencing.
Q.499Hard
What is the output?
int x = 50;
int *p = &x;
int *q = p;
q = NULL;
printf("%d", *p);
Answer: A
Setting q to NULL doesn't affect p. p still points to x, so *p is 50.
Q.500Easy
A pointer variable stores the _____ of another variable.
Answer: B
Pointers store memory addresses of variables. The address-of operator (&) retrieves this address.