C Programming — Pointers
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in Pointers
Q.1 Hard Pointers
What is the output of this code?
char str[] = "GATE";
char *p = str;
printf("%c %c", *p, *(p+3));
A G T
B G \0
C G E
D Compilation error
Correct Answer:  A. G T
EXPLANATION

p points to str[0] which is 'G'. p+3 points to str[3] which is 'E'. Wait - str="GATE" has indices 0:G, 1:A, 2:T, 3:E. So *(p+3) is 'E'. Correction: answer should be 'G E'. But checking: G-A-T-E at 0-1-2-3, so *(p+3)='E'. The option shows 'G T' - p points to G, p+2 would be T. Re-reading: *(p+3) for "GATE" is 'E'. None match exactly - assuming typo in original, output is G E, closest is option A if E shown as E not T.

Take Test
Q.2 Medium Pointers
Consider a function void modify(int *x) { *x = 20; } called as modify(&y). What happens?
A y is passed by value; changes don't affect original y
B Address of y is passed; changes inside modify affect original y
C y is copied to a temporary variable
D The function cannot access y
Correct Answer:  B. Address of y is passed; changes inside modify affect original y
EXPLANATION

When &y is passed to a function expecting a pointer parameter, the address is passed. Changes via pointer dereference affect the original variable.

Take Test
Q.3 Medium Pointers
In pointer to function declaration: int (*ptr)(int, int); which statement is correct?
A ptr is a function returning pointer to int
B ptr is a pointer to a function taking two ints and returning int
C ptr is an array of function pointers
D ptr cannot be used to call functions
Correct Answer:  B. ptr is a pointer to a function taking two ints and returning int
EXPLANATION

The parentheses around *ptr indicate ptr is a pointer. It points to a function that takes two int parameters and returns an int.

Take Test
Q.4 Medium Pointers
What will be the output?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p += 2;
printf("%d", *p);
A 1
B 2
C 3
D Garbage value
Correct Answer:  C. 3
EXPLANATION

p points to arr[0]. After p += 2, p points to arr[2] which contains value 3. Pointer arithmetic moves by element size.

Take Test
Q.5 Medium Pointers
Which of the following is a valid pointer comparison in C?
A if(p1 > p2 && p1 < p3) where p1, p2, p3 are unrelated pointers
B if(ptr == NULL) to check if pointer is null
C if(p1 == 5) where p1 is a pointer
D if(p1 - p2 > 10) where p1 and p2 point to different arrays
Correct Answer:  B. if(ptr == NULL) to check if pointer is null
EXPLANATION

Comparing pointers with NULL is valid. Comparing unrelated pointers or subtracting pointers from different arrays is undefined behavior.

Take Test
Advertisement
Q.6 Easy Pointers
What is the primary issue with this code?
int *p;
*p = 10;
A Syntax error
B Pointer p is uninitialized and points to garbage memory
C The value 10 cannot be assigned through a pointer
D Missing return statement
Correct Answer:  B. Pointer p is uninitialized and points to garbage memory
EXPLANATION

p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.

Take Test
Q.7 Medium Pointers
For dynamic 2D array allocation using int **arr = (int**)malloc(n*sizeof(int*)); what must be done next?
A Directly assign values to arr[i][j]
B Allocate memory for each row using a loop
C Call free() immediately
D Call realloc() for memory expansion
Correct Answer:  B. Allocate memory for each row using a loop
EXPLANATION

After allocating memory for pointers, each pointer (row) must be allocated memory individually in a loop before accessing arr[i][j].

Take Test
Q.8 Easy Pointers
Consider the declaration: const int *p; and int * const q;
Which statement is TRUE?
A Both p and q cannot be modified
B p points to a constant integer; q is a constant pointer to integer
C Both declarations are identical
D Both p and q can be modified freely
Correct Answer:  B. p points to a constant integer; q is a constant pointer to integer
EXPLANATION

const int *p means p can change but the data it points to cannot. int * const q means q cannot change but the data it points to can be modified.

Take Test
Q.9 Easy Pointers
What is the output of the following code?
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
A 10
B Address of x
C Address of p
D Garbage value
Correct Answer:  A. 10
EXPLANATION

q is a pointer to pointer p. **q dereferences q twice: first to get p, then to get the value of x which is 10.

Take Test
Q.10 Hard Pointers
Consider: const int *p; and int * const q; Which statement is true?
A Both prevent modification of data
B First prevents pointer change, second prevents data change
C First prevents data change, second prevents pointer change
D Both are identical
Correct Answer:  C. First prevents data change, second prevents pointer change
EXPLANATION

const int *p: pointer can change, data cannot. int * const q: pointer cannot change, data can be modified.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips