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()
{
char* str = “learnown”;
printf(“%c\n” , *(str++ + 2)+3);
printf(“%c\n” , *++str+2);
printf(“%c\n” , *–str-1);
}

  1. d, c, l
  2. d, c, d
  3. n, c, garbage character
  4. n, c, l

Answer :

Ans : 2 ;

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

  1. 5, garbage value, , 5
  2. 5, 5, 5
  3. 5, garbage value, garbage value
  4. 5, 5, garbage value

Answer :

Ans : 1 ;

What is the output of this C code?
#include<stdio.h>
void main()
{
int arr[5] = {9 , 3, 4 , 6 , 7},i;
int* ptr[5];
for(i=0 ; i<5; i++)
{
ptr[i] = arr+i;
}
printf(“%d” , *(*(ptr+1)) + arr[3]);
}

  1. Compile time error
  2. 15
  3. 9
  4. 7

Answer :

Ans : 3 ;

What is the output of this C code?
#include<stdio.h>
void main()
{
char* s[5] = {“one”, “two”, “three”, “four”,”five”};
int i=0,j=4;
char* t;
while(++i < j–)
{
t = s[i];
s[i] = s[j];
s[j] = t;
}
printf(“%s”,*(s + ++i));
}

  1. two
  2. three
  3. four
  4. five

Answer :

Ans : 4 ;

What is the output of this C code?
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf(“%d”, **r);
}

  1. Compile time error
  2. 1
  3. 2
  4. 3

Answer :

Ans : 1 ;

What is the output of this C code?
#include<stdio.h>
void main()
{
char *s[ ] = {“black”, “white”, “pink”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s};
char ***p;
p = ptr;
++p;
printf(“%s\n”, (*(*p+1)+1)+2);
}

  1. ink
  2. ite
  3. let
  4. ack

Answer :

Ans : 3 ;

What is the output of this C code?
#include<stdio.h>
int main()
{
char *s[]={“black”,”white”,”pink”,”violet”};
char **ptr[] = {s+1, s, s+3, s+2};
char ***p;
p = ptr;
p+1;
printf(“%c\n”, *(*(*++p+1))+3);
return 0;
}

  1. l
  2. k
  3. t
  4. z

Answer :

Ans : 4 ;

What is the output of this C code?
#include<stdio.h>
void main()
{
char* str = “learnown”;
printf(“%c\n”,*((str– +2)+1)-3);
printf(“%c\n”, *(–str + 3)-32);
printf(“%c\n”,*(++str+2)+4);
}

  1. o, E, o
  2. n, E, i
  3. o, E, i
  4. o, E, n

Answer :

Ans : 3 ;

Pointers – Objective –  Part 1

Share this