Back to Practice C Programming

Pointers - Practice MCQs for CCAT

50 Questions Section B: Programming C Programming

Pointers Question Bank for C-CAT

Topic-wise Pointers MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
What is a pointer in C?
AVariable storing value
BVariable storing address
CFunction
DKeyword
Show Answer & Explanation

Correct Answer: B - Variable storing address

A pointer is a variable that stores the memory address of another variable.

Q2.
Which operator is used to get the address of a variable?
A&
B*
C#
D%
Show Answer & Explanation

Correct Answer: A - &

The address-of operator (&) returns the memory address of a variable.

Q3.
Which operator is used to access the value pointed by a pointer?
A&
B*
C->
D.
Show Answer & Explanation

Correct Answer: B - *

The dereference operator (*) accesses the value stored at the address.

Q4.

What will be the output?

int x = 10;
int *p = &x;
printf("%d", *p);
AAddress of x
BGarbage
C10
DError
Show Answer & Explanation

Correct Answer: C - 10

Pointer p stores address of x and *p gives the value of x.

Q5.

What will be the output?

int x = 5;
int *p = &x;
*p = 8;
printf("%d", x);
A5
BGarbage
C8
DError
Show Answer & Explanation

Correct Answer: C - 8

Changing *p modifies the original variable x.

Q6.
What is a NULL pointer?
APointer with garbage value
BUninitialized pointer
CPointer pointing to 0 address
DDangling pointer
Show Answer & Explanation

Correct Answer: C - Pointer pointing to 0 address

NULL pointer does not point to any valid memory location.

Q7.
What happens if a NULL pointer is dereferenced?
AReturns 0
BUndefined behavior
CCompilation error
DReturns garbage
Show Answer & Explanation

Correct Answer: B - Undefined behavior

Dereferencing NULL pointer leads to runtime error or crash.

Q8.
What is a wild pointer?
APointer with value 0
BPointer to pointer
CPointer not initialized
DConstant pointer
Show Answer & Explanation

Correct Answer: C - Pointer not initialized

Wild pointer points to an unknown memory location.

Q9.

What will be the output?

int a = 10;
int *p = &a;
printf("%d", *p + 1);
A10
BAddress
C11
DError
Show Answer & Explanation

Correct Answer: C - 11

Dereferenced value 10 is incremented by 1.

Q10.

What will be the output?

int arr[3] = {1,2,3};
int *p = arr;
printf("%d", *p);
A1
B2
CAddress
DError
Show Answer & Explanation

Correct Answer: A - 1

Array name stores base address, so *p accesses first element.

Q11.

What will be the output?

int arr[3] = {1,2,3};
int *p = arr;
printf("%d", *(p+1));
A1
B2
C3
DGarbage
Show Answer & Explanation

Correct Answer: B - 2

Pointer arithmetic moves pointer to next element.

Q12.
Pointer arithmetic depends on:
AAddress size
BOS
CData type size
DCompiler
Show Answer & Explanation

Correct Answer: C - Data type size

Incrementing pointer moves by size of data type.

Q13.

What will be the output?

int x = 5;
int *p = &x;
p++;
printf("%d", *p);
A5
BGarbage
C6
DCompilation error
Show Answer & Explanation

Correct Answer: B - Garbage

Pointer moves to next memory location which is not valid for x.

Q14.
Which pointer can point to any data type?
Aint pointer
Bchar pointer
CNULL pointer
Dvoid pointer
Show Answer & Explanation

Correct Answer: D - void pointer

void pointer is a generic pointer type.

Q15.
What is required before dereferencing a void pointer?
ANothing
BInitialization
CFree memory
DType casting
Show Answer & Explanation

Correct Answer: D - Type casting

Void pointer must be typecasted before dereferencing.

Q16.
What is a dangling pointer?
AUninitialized pointer
BPointer to array
CPointer with NULL
DPointer to freed memory
Show Answer & Explanation

Correct Answer: D - Pointer to freed memory

Dangling pointer points to memory that has been deallocated.

Q17.

What will be the output?

int a = 10;
int *p = &a;
int **q = &p;
printf("%d", **q);
AAddress
BGarbage
C10
DError
Show Answer & Explanation

Correct Answer: C - 10

Pointer to pointer dereferences twice to get value.

Q18.
Which of the following is correct declaration of pointer to pointer?
Aint *p;
Bint p**;
Cint **p;
Dint &p;
Show Answer & Explanation

Correct Answer: C - int **p;

Double asterisk declares pointer to pointer.

Q19.

What will be the output?

int arr[5];
printf("%d", sizeof(arr));
A4
B5
CDepends on compiler
D20
Show Answer & Explanation

Correct Answer: D - 20

Array of 5 integers occupies 20 bytes (assuming 4 bytes each).

Q20.

What will be the output?

int arr[5];
int *p = arr;
printf("%d", sizeof(p));
A4
BDepends on compiler
C20
D8
Show Answer & Explanation

Correct Answer: B - Depends on compiler

Pointer size depends on system architecture (32-bit/64-bit).

Q21.
Which is safer practice to avoid wild pointers?
AUsing free()
BInitializing pointer to NULL
CUsing goto
DUsing static
Show Answer & Explanation

Correct Answer: B - Initializing pointer to NULL

Initializing pointers avoids accidental access.

Q22.
Which statement is true?
APointer stores value
BPointer stores address
CPointer stores instruction
DPointer stores constant
Show Answer & Explanation

Correct Answer: B - Pointer stores address

Pointers store memory addresses.

Q23.

What will be the output?

int x = 10;
int *p = &x;
printf("%d", sizeof(*p));
A4
B2
C8
DDepends on compiler
Show Answer & Explanation

Correct Answer: A - 4

sizeof(*p) is size of int.

Q24.
Which of the following is invalid?
Aint *p;
Bint **p;
Cint *p = NULL;
Dint &p;
Show Answer & Explanation

Correct Answer: D - int &p;

Reference operator (&) is not valid in C.

Q25.

What will be the output?

int a = 5;
int *p = &a;
printf("%d", (*p)++);
A6
B5
CGarbage
DError
Show Answer & Explanation

Correct Answer: B - 5

Post-increment prints value first, then increments.

Q26.

What is the output?

int x = 10;
int *p = &x;
*p = 25;
printf("%d", x);
A10
BAddress of x
C25
DCompilation error
Show Answer & Explanation

Correct Answer: C - 25

p is a pointer to x. Dereferencing p with *p = 25 modifies the value stored at x's address. So x becomes 25. This demonstrates how pointers provide indirect access to variables.

Q27.

What is the output?

int arr[] = {10, 20, 30, 40, 50};
int *p = arr;
printf("%d", *(p + 3));
A30
B50
C10
D40
Show Answer & Explanation

Correct Answer: D - 40

p points to arr[0]. Adding 3 to p moves it forward by 3 integer positions (pointer arithmetic accounts for the size of int). So *(p + 3) is equivalent to arr[3], which is 40.

Q28.

What is the output?

int a = 5, b = 10;
int *p = &a, *q = &b;
printf("%d", *p + *q);
A15
BAddress sum
C5
DCompilation error
Show Answer & Explanation

Correct Answer: A - 15

*p dereferences p to get the value of a (5), and *q dereferences q to get the value of b (10). The expression *p + *q adds these values: 5 + 10 = 15.

Q29.
What does a NULL pointer represent in C?
AA pointer that doesn't point to any valid memory location
BA pointer to address 0 in memory
CAn uninitialized pointer
DA pointer to the stack
Show Answer & Explanation

Correct Answer: A - A pointer that doesn't point to any valid memory location

A NULL pointer is a special pointer value that indicates the pointer doesn't point to any valid object or function. It is typically defined as ((void*)0). Dereferencing a NULL pointer causes undefined behavior, usually a segmentation fault.

Q30.

What is the output?

int arr[] = {2, 4, 6, 8, 10};
int *p = arr + 4;
printf("%d", p[-2]);
A6
B4
C8
D10
Show Answer & Explanation

Correct Answer: A - 6

p points to arr[4] (value 10). The expression p[-2] is equivalent to *(p - 2), which points to arr[4-2] = arr[2] = 6.

Q31.

What is the output?

int x = 100;
int *p = &x;
int **pp = &p;
printf("%d", **pp);
AAddress of p
BAddress of x
CCompilation error
D100
Show Answer & Explanation

Correct Answer: D - 100

pp is a pointer to pointer. *pp gives p (pointer to x), and **pp dereferences again to get the value of x, which is 100. This is a two-level indirection: pp → p → x.

Q32.
What is the difference between int *p and int **p?
ANo difference; both are pointers to int
B*p is a pointer to int, **p is a pointer to a pointer to int
C*p is an integer, **p is a pointer
D**p is a double pointer storing two addresses
Show Answer & Explanation

Correct Answer: B - *p is a pointer to int, **p is a pointer to a pointer to int

'int *p' declares p as a pointer that stores the address of an int variable. 'int **p' declares p as a pointer that stores the address of another pointer (which in turn points to an int). This allows two levels of indirection.

Q33.

What is the output?

void modify(int **pp) {
    static int val = 50;
    *pp = &val;
}
int main() {
    int x = 10;
    int *p = &x;
    modify(&p);
    printf("%d", *p);
}
A10
BSegmentation fault
C0
D50
Show Answer & Explanation

Correct Answer: D - 50

The function modify() receives a pointer to pointer. *pp = &val changes what p points to — now p points to the static variable val (50) instead of x. Since val is static, it persists after the function returns. *p now gives 50.

Q34.

What is the output?

char *str = "Hello";
printf("%c", *(str + 1));
AH
Bo
Cl
De
Show Answer & Explanation

Correct Answer: D - e

str points to the first character 'H' of the string literal "Hello". str + 1 advances the pointer by one character position, pointing to 'e'. Dereferencing with * gives 'e'.

Q35.
What happens when you increment a pointer to int by 1?
AThe address increases by 1 byte
BThe address increases by sizeof(int) bytes
CThe value pointed to increases by 1
DCompilation error
Show Answer & Explanation

Correct Answer: B - The address increases by sizeof(int) bytes

Pointer arithmetic in C is scaled by the size of the pointed-to type. Incrementing an int pointer by 1 advances the address by sizeof(int) bytes (typically 4 bytes), not by 1 byte. This ensures the pointer moves to the next integer in memory.

Q36.

What is the output?

int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
int *q = arr + 4;
printf("%ld", q - p);
A4
B16
C5
D20
Show Answer & Explanation

Correct Answer: A - 4

When two pointers to the same array are subtracted, the result is the number of elements between them (not bytes). q points to arr[4] and p points to arr[0], so q - p = 4 elements.

Q37.
Which statement correctly declares a function pointer that points to a function taking two ints and returning an int?
Aint *fptr(int, int);
Bint *(fptr)(int, int);
Cint (*fptr)(int, int);
D(int*) fptr(int, int);
Show Answer & Explanation

Correct Answer: C - int (*fptr)(int, int);

'int (*fptr)(int, int);' correctly declares fptr as a pointer to a function that takes two int parameters and returns int. The parentheses around (*fptr) are essential. Without them, 'int *fptr(int, int)' declares a function returning int*.

Q38.

What is the output?

int a = 10, b = 20, c = 30;
int *arr[3] = {&a, &b, &c};
printf("%d", *arr[1]);
A10
B30
C20
DAddress of b
Show Answer & Explanation

Correct Answer: C - 20

arr is an array of 3 int pointers. arr[0] = &a, arr[1] = &b, arr[2] = &c. *arr[1] dereferences arr[1] (which holds &b) to give the value of b, which is 20.

Q39.

What is the output?

void increment(int *p) {
    (*p)++;
}
int main() {
    int x = 7;
    increment(&x);
    increment(&x);
    printf("%d", x);
}
A9
B8
C7
D14
Show Answer & Explanation

Correct Answer: A - 9

Each call to increment() dereferences p and increments the value by 1. After first call: x = 8. After second call: x = 9. The pointer provides pass-by-reference semantics.

Q40.

What is the output?

char str[] = "CDAC Exam";
char *p = str;
while(*p != '\0') {
    if(*p == ' ') {
        printf("_");
    } else {
        printf("%c", *p);
    }
    p++;
}
ACDAC_Exam
BCDAC Exam
CCDAC
DC_D_A_C_ _E_x_a_m
Show Answer & Explanation

Correct Answer: A - CDAC_Exam

The pointer p traverses each character of the string. When it encounters a space character ' ', it prints underscore '_' instead. All other characters are printed as-is. So 'CDAC Exam' becomes 'CDAC_Exam'.

Q41.

What is the output?

int x = 5;
int *p = &x;
int **q = &p;
**q = 20;
printf("%d %d %d", x, *p, **q);
A5 5 5
B5 20 20
C20 20 20
D20 5 20
Show Answer & Explanation

Correct Answer: C - 20 20 20

**q = 20 modifies the value at the location pointed to by the pointer that q points to. Since q → p → x, **q = 20 sets x = 20. Now x, *p, and **q all refer to the same memory location containing 20.

Q42.

What is wrong with this code?

int *p;
*p = 10;
printf("%d", *p);
ADereferencing an uninitialized (wild) pointer — undefined behavior
BNothing; it prints 10
CSyntax error in pointer declaration
DCannot assign to *p directly
Show Answer & Explanation

Correct Answer: A - Dereferencing an uninitialized (wild) pointer — undefined behavior

The pointer p is declared but not initialized — it contains a garbage address. Dereferencing it with *p = 10 writes to an unknown memory location, causing undefined behavior (likely a segmentation fault). Always initialize pointers before use.

Q43.

What is the output?

int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int *p = &arr[0][0];
printf("%d", *(p + 5));
A5
B8
C4
D6
Show Answer & Explanation

Correct Answer: D - 6

A 2D array is stored in row-major order in memory: 1,2,3,4,5,6,7,8,9. p points to arr[0][0] (value 1). p+5 points to the 6th element, which is 6. So *(p+5) = 6.

Q44.

What is the output?

int x = 10;
int *p1 = &x;
int *p2 = &x;
printf("%d", (p1 == p2));
A0
B1
C10
DAddress of x
Show Answer & Explanation

Correct Answer: B - 1

Both p1 and p2 point to the same variable x, so they hold the same address. Comparing them with == returns 1 (true). Pointer comparison checks if two pointers point to the same memory location.

Q45.

What is the output?

void allocate(int **pp) {
    *pp = (int*)malloc(sizeof(int));
    **pp = 42;
}
int main() {
    int *p = NULL;
    allocate(&p);
    printf("%d", *p);
    free(p);
}
A42
B0
CSegmentation fault
DCompilation error
Show Answer & Explanation

Correct Answer: A - 42

The function allocate() receives a pointer to pointer. *pp = malloc() makes the original pointer p in main() point to newly allocated memory. **pp = 42 stores 42 in that memory. Back in main(), *p gives 42. The memory is properly freed afterward.

Q46.
What does the expression arr[i] translate to internally in C?
A*(arr + i)
B&(arr + i)
C*(arr - i)
Darr * i
Show Answer & Explanation

Correct Answer: A - *(arr + i)

In C, arr[i] is syntactic sugar for *(arr + i). The array name arr is a pointer to the first element. Adding i performs pointer arithmetic to reach the i-th element, and * dereferences it. This also means i[arr] is valid and equivalent!

Q47.

What is the output?

void swap(int **a, int **b) {
    int *temp = *a;
    *a = *b;
    *b = temp;
}
int main() {
    int x = 5, y = 10;
    int *px = &x, *py = &y;
    swap(&px, &py);
    printf("%d %d", *px, *py);
}
A5 10
BCompilation error
C0 0
D10 5
Show Answer & Explanation

Correct Answer: D - 10 5

The function swaps the pointers px and py (not the values they point to). After swap, px points to y and py points to x. So *px = 10 and *py = 5. The original variables x and y are unchanged, but the pointers now reference each other's target.

Q48.

What is the output?

const int *p;
int x = 10, y = 20;
p = &x;
printf("%d ", *p);
p = &y;
printf("%d", *p);
A10 20
B10 10
CCompilation error
D20 20
Show Answer & Explanation

Correct Answer: A - 10 20

'const int *p' means the value pointed to cannot be changed via p, but p itself can be reassigned. p first points to x (10), then is reassigned to point to y (20). Both dereferences are reads (allowed with const). Output: 10 20.

Q49.

What is the output?

char *ptr;
char str[] = "Programming";
ptr = str;
ptr += 3;
printf("%s", ptr);
APro
Bogramming
Cramming
Dgramming
Show Answer & Explanation

Correct Answer: D - gramming

ptr initially points to str[0] ('P'). After ptr += 3, it points to str[3] ('g'). Printing with %s from that position gives the substring starting from 'g': "gramming".

Q50.

What is the output?

int compute(int a, int b) { return a + b; }
int process(int a, int b) { return a * b; }

int main() {
    int (*fp)(int, int);
    fp = compute;
    printf("%d ", fp(3, 4));
    fp = process;
    printf("%d", fp(3, 4));
}
A12 7
B7 12
C7 7
D12 12
Show Answer & Explanation

Correct Answer: B - 7 12

fp is a function pointer. First it points to compute: fp(3,4) = 3+4 = 7. Then it's reassigned to process: fp(3,4) = 3*4 = 12. Function pointers enable runtime polymorphism in C. Output: 7 12.

Showing 1-10 of 50 questions