Machine-translated by Google. Questions are authored in English.
Top

Pointers Questions and Answers

11.

What will be the following C code print ?

int a[] = {1,2,3,4};
int *p = a ;
printf("%d", *(++p) + 2);

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

The program prints 4.

  1. int *p = a; makes p point at a[0], which holds 1.
  2. ++p is a pre-increment, so p moves to a[1] before it is used.
  3. *(++p) therefore reads a[1], which is 2.
  4. 2 + 2 gives 4, printed with %d.

3 is what you get from *p + 2 without the increment (1 + 2). 5 would need p to move two places, to a[2], which holds 3. There is no compilation error: incrementing a pointer variable is legal, and the parentheses make the increment apply to p before the dereference.

Please log in or register to report this question.

12.

In C, which of the following is TRUE about arrays and pointers ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The true statement is that array[i] is equivalent to *(array + i).

C defines subscripting in terms of pointer arithmetic: in an expression the array name becomes a pointer to its first element, adding i moves the pointer i elements along, and the dereference reads that element. The two forms are interchangeable by the language definition (which is also why the odd form i[array] compiles).

sizeof(array) gives the size of the whole array, for example 40 for ten 4-byte ints, not the size of a pointer; they coincide only for an array parameter, which is really a pointer. An array name is not a modifiable lvalue, so array++ is an error. Since C is true, 'None of these' is wrong.

Please log in or register to report this question.

13.

What is the output of the following pseudocode?

int arr[] = {1, 2, 3, 4, 5}
int *ptr = arr + 2
print(*ptr + *(ptr + 1))

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The output is 7.

The array holds 1, 2, 3, 4, 5 at indices 0 to 4. arr + 2 points to index 2, so *ptr is 3. ptr + 1 points to index 3, so *(ptr + 1) is 4. The sum is 3 + 4 = 7.

Pointer arithmetic moves by whole elements, not bytes, so arr + 2 is the third element. 5 is the sum of indices 1 and 2 (2 + 3), a slip of taking arr + 2 as the second element. 9 is 4 + 5, a slip of one position too far, and 3 is the first value alone.

Please log in or register to report this question.

14.

If int *p points to arr[2], then (p+1) points to

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

p + 1 points to arr[3].

In pointer arithmetic, adding 1 to a pointer moves it forward by one element of the type it points to, not by one byte. If p holds the address of arr[2], then p + 1 holds the address of the next int, arr[3]; the compiler scales the 1 by sizeof(int) automatically.

arr[1] would be p - 1. arr[2]+1 describes adding 1 to the value stored in arr[2], not moving the pointer, and the result can be determined exactly from the rules of pointer arithmetic.

Please log in or register to report this question.

15.

What is the output of the following program ?

#include<stdio.h>
void f(int *p, int *q) {
    p=q;
    *p=2;
}
int i=0, j=1;
int main(void){
    f(&i, &j);
    printf("%d %d\n", i, j);
    }

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: D

The program prints 0 2.

C passes arguments by value, so p and q are local copies of the addresses &i and &j. Walk through f:

  1. p=q; changes only the local copy p, which now holds &j. The variable i is untouched.
  2. *p=2; writes 2 through p, that is into j.

Back in main, i is still 0 and j is now 2, so printf prints 0 2. '2 1' is what you would get if *p=2 still wrote to i; '2 2' assumes p=q changed main's pointer; '0 1' ignores the write through p altogether.

Please log in or register to report this question.

16.

What is the output of the following program ?

#include <stdio.h>
int f (int *a, int n)
{
if(n<=0) return 0;
else if (*a%2 = = 0) return *a + f(a+1, n-1);
else return *a - f(a+1, n-1);
}
int main(void)
{
int a[] = {12, 7, 13, 4, 11, 6};
printf("%d", f(a,6));
return 0;
}

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The program prints 15.

f adds an even element and subtracts the result of the rest after an odd element. Work from the end of the array {12, 7, 13, 4, 11, 6}:

\[ \begin{aligned} f(\{6\}) &= 6 + 0 = 6 \\ f(\{11,6\}) &= 11 - 6 = 5 \\ f(\{4,\ldots\}) &= 4 + 5 = 9 \\ f(\{13,\ldots\}) &= 13 - 9 = 4 \\ f(\{7,\ldots\}) &= 7 - 4 = 3 \\ f(\{12,\ldots\}) &= 12 + 3 = 15 \end{aligned} \]

The trap is reading it as an alternating sum of the elements; the subtraction applies to the whole remaining result, not to the next element alone. 5 is the value at the 11 step, and -9 and 19 come from sign slips.

Please log in or register to report this question.

17.

What does the following declaration mean ? int (*ptr) [10];

Exam Year(s)

UGC NET - 2013,

Answer: B

The declaration int (*ptr)[10]; means that ptr is a pointer to an array of 10 integers. The parentheses bind the star to ptr first, so ptr is a pointer, and the [10] then describes the thing it points to.

An array of 10 pointers to integers would be written int *ptr[10], without the parentheses. A plain array of 10 integers would be int ptr[10]. Since the declaration is a valid one with a clear meaning, 'none of the above' is wrong.

Please log in or register to report this question.

18.

What is the output of this C code?

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **m);
}

 

Answer: A

Correct answer: 5 5 5

Each dereference removes one level. k is 5; p holds the address of k, so *p is 5; and m holds the address of p, so *m is p and **m is 5. All three names reach the same object by paths of different length, which is the whole point of the double pointer.

Please log in or register to report this question.

19.

What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

Answer: B

Correct answer: *(*(*(*(a+i)+j)+k)+l)

Each subscript is defined as a dereference of a sum: x[y] means *(x+y). Applying that rule four times, from the outside in, gives one dereference for every subscript.

\[ a[i][j][k][l] \equiv *(*(*(*(a+i)+j)+k)+l) \]

The options without the asterisks compute addresses but never read through them. Note that the pointer arithmetic is scaled by the size of the sub-array at each level, which is why the array's dimensions must be known to the compiler.

Please log in or register to report this question.

20.

What will be the output of the program If the integer is 4bytes long?

#include <stdio.h>

int main()
{
    int ***r, **q, *p, i=8;
    p = &i;
    q = &p;
    r = &q;
    printf("%d, %d, %d\n", *p, **q, ***r);
    return 0;
}

 

Answer: A

Correct answer: 8, 8, 8

Each level of indirection is undone by one dereference. p points to i, q points to p, and r points to q.

So *p reaches i directly; **q goes through p to i; and ***r goes through q and p to i. All three arrive at the same object and print 8. The distractors offer addresses, which would appear only if fewer dereferences were applied than there are levels of indirection.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Pointers Questions and Answers || Pointers MCQ Questions and Answers || Pointers GK Questions and Answers || Pointers GK MCQ Questions || Pointers Multiple Choice Questions and Answers || Pointers GK || GK on Pointers || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming