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

Pointers Questions and Answers

11.

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.

12.

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.

13.

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.

14.

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.

15.

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.

16.

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.

17.

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.

18.

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.

19.

What is the output of this C code?

int main()
{
int i = 10;
int *p = &i;
foo(&p);
printf("%d ", *p);
printf("%d ", *p);
}
void foo(int **const p)
{
int j = 11;
*p = &j;
printf("%d ", **p);
}

 

Answer: B

Correct answer: 11 11 Undefined-value

int **const p makes the parameter itself constant, but *p is not, so *p = &j is legal and the caller’s pointer is redirected to j. The first two prints give 11, one inside foo and one immediately after it returns. By the third, j’s lifetime has ended and the value is indeterminate - compare with the previous question, where the const sits in the other position and the code will not compile at all.

Please log in or register to report this question.

Answer: C

Correct answer: j is a pointer to an int and stores address of i

The declaration int *j = &i; declares j as a pointer to int and initialises it with the address of i.

The asterisk belongs to the declarator, not to the type specifier - the declaration reads "*j is an int", hence j is a pointer to int. i is an ordinary int and no pointer at all, and j has one level of indirection, not two, which the number of asterisks makes plain.

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