C Technical Interview Questions on Pointers

These C Technical Interview Questions On Pointers post providing basic, intermediate and Hard level examples in C Pointers. The Practice of these examples makes you good in C programming.


What is the output of this C code?
#include<stdio.h>
void main()
{
int i=100;
int* ptr = &i;
printf(“%d\n”,*ptr);
printf(“%d\n”,*(*(&ptr)));
}

  1. 100 , address
  2. 100 , garbage value
  3. 100 , 100
  4. Compile time error

Answer :

Ans : 3

What is the output of this C code?
#include <stdio.h>
void main()
{
char* cp ;
printf(“size of char* : %d\n”, sizeof(cp));
printf(“size of float* : %d\n”, sizeof(double*));
}

  1. 1, 4
  2. 2, 2
  3. 1, 8
  4. 2, 8

Answer :

Ans : 2 ; Any pointer occupies 2 bytes in C language.

How many bytes the address increases?
#include <stdio.h>
int x = 0;
void main()
{
int *ptr = &x;
printf(“%p\n”, ptr);
x++;
printf(“%p\n “, ptr);
}

  1. Same address 2 times
  2. 2 consecutive locations
  3. Compile time error
  4. None of the above

Answer :

Ans : 1

What is the output of this C code?
#include <stdio.h>
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf(“%d,%d/n”, *ptr, a);
}

  1. 10, 10
  2. 10, 11
  3. 11, 10
  4. 11 , 11

Answer :

Ans : 4

What is the output of this C code?
#include <stdio.h>
int *f();
int main()
{
int *p = f();
printf(“%d\n”, *p);
}
int *f()
{
int j = 10;
return &j;
}

  1. Compile time error
  2. 10
  3. Garbage value
  4. None of the above

Answer :

Ans : 2

What is the output of this C code?
#include<stdio.h>
void main()
{
int r1,r2;
int (*fptr)(int,int);
fptr = &add;
r3=fptr(30,50);
fptr = &sub;
r4=fptr(30,50);
printf(“%d,%d”,r1,r2);
}
int add(int x, int y){
return x+y;
}
int sub(int x, int y){
return x-y;
}

  1. Compile time error
  2. 80, 80
  3. 80, -20
  4. -20, -20

Answer :

Ans: 1 ; Prototype mismatch to assing address to pointer variable

What is the output of this C code?
#include<stdio.h>
int main()
{
void *vp;
char ch=74, *cp=”JACK”;
int j=65;
vp = &ch;
printf(“%c”, *(char*)vp);
vp = &j;
printf(“%c”, *(int*)vp);
vp = cp;
printf(“%s”, (char*)vp+3);
return 0;
}

  1. JACK
  2. JAK
  3. JK
  4. KAJ

Answer :

Ans : 2

What is the output of this C code?
void main()
{
int arr[5] = {10,20,30,40,50},i;
int* ptr;
ptr = arr;
printf(“%u\n”, *++ptr + 3);
printf(“%u\n”, *(ptr– + 2) + 5);
printf(“%u\n”, *(ptr+3)-10);
}

  1. 23, 35, 30
  2. 14, 45, 30
  3. 23, 45, 30
  4. 14, 35, 30

Answer :

Ans : 3 ;

What is the output of this C code?
#include <stdio.h>
void f(int*);
int main()
{
int i = 10;
f((&i)++);
}
void f(int *p)
{
printf(“%d\n”, *p);
}

  1. Compile time error
  2. 10
  3. Garbage value
  4. 11

Answer :

Ans : 1

What is the output of this C code?
void main()
{
int arr[5] = {10,20,30,40,50},i;
int* ptr;
ptr = arr;
printf(“%u,%u,%u\n”, *ptr– + 1, *(ptr++ + 1) , *(ptr– + 2)-5);
}

  1. 25, 10, 11
  2. 10, 10, 25
  3. 11, 10, 23
  4. 11, 10, 25

Answer :

Ans : 4 ; Expessions evaluation from right side but printing from left side

Pointers – Technical – Part 2

Share this