C Programming — Pointers
C language from basics to advanced placement prep
21 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 21 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 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
Q.3 Hard Pointers
What is the relationship between arrays and pointers?
A Arrays are pointers
B Pointers are arrays
C Array name decays to pointer in most contexts
D They are unrelated
Correct Answer:  C. Array name decays to pointer in most contexts
EXPLANATION

Array name acts as pointer to first element in expressions but they're distinct. &arr and arr differ in type.

Take Test
Q.4 Hard Pointers
For dynamic 2D array: int **arr = (int**)malloc(n * sizeof(int*)); What's missing?
A Nothing, code is complete
B Allocating memory for each row
C Casting malloc result
D Type checking
Correct Answer:  B. Allocating memory for each row
EXPLANATION

This allocates row pointers only. Each row needs allocation: arr[i] = (int*)malloc(m * sizeof(int));

Take Test
Q.5 Hard Pointers
What is the output of: printf("%p", NULL);?
A 0x0
B NULL
C Implementation-defined (typically 0x0 or empty)
D Compilation error
Correct Answer:  C. Implementation-defined (typically 0x0 or empty)
EXPLANATION

%p prints pointer values. NULL representation depends on implementation, commonly shown as 0x0 or (nil).

Take Test
Advertisement
Q.6 Hard Pointers
In pointer to function: int (*ptr)(int, int); What does this declare?
A Function returning pointer to int
B Pointer to function returning int with 2 int parameters
C Array of pointers
D Pointer to array of ints
Correct Answer:  B. Pointer to function returning int with 2 int parameters
EXPLANATION

Parentheses around *ptr give pointer priority. It's a pointer to a function taking 2 ints and returning int.

Take Test
Q.7 Hard Pointers
What is the difference between arr and &arr if arr is an array?
int arr[5];
A Both are identical
B arr is pointer to first element, &arr is pointer to whole array
C &arr is pointer to first element, arr is pointer to whole array
D They have different sizes
Correct Answer:  B. arr is pointer to first element, &arr is pointer to whole array
EXPLANATION

arr decays to pointer to first element (int*). &arr is pointer to whole array (int(*)[5]). Pointer arithmetic differs.

Take Test
Q.8 Hard Pointers
What will be printed?
int *p = (int*)malloc(5 * sizeof(int));
int *q = p;
p = NULL;
free(q);
A Compilation error
B Memory leak
C Program runs successfully
D Double free error
Correct Answer:  C. Program runs successfully
EXPLANATION

q still holds the address even though p is NULL. free(q) properly deallocates memory.

Take Test
Q.9 Hard Pointers
What is malloc(0) likely to return?
A NULL pointer
B Valid pointer to 0 bytes
C Garbage value
D Compilation error
Correct Answer:  B. Valid pointer to 0 bytes
EXPLANATION

malloc(0) behavior is implementation-defined but typically returns a valid pointer. Freeing it is safe.

Take Test
Q.10 Hard Pointers
Consider: int arr[] = {1,2,3,4,5}; int *p = arr + 2; What is arr - p?
A -2
B 2
C Address difference
D Compilation error
Correct Answer:  A. -2
EXPLANATION

arr points to arr[0], p points to arr[2]. arr - p = -2 (p is 2 positions ahead).

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