C Practice Test on Pointers

This “C Practice Test on Pointers” providing set of technical and objective type questions on Pointers to test your programming skills.


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);
}

 
 
 
 

2. 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*));
}

 
 
 
 

3. 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);
}

 
 
 
 

4. What is the output of this C code?
#include<stdio.h>
int main()
{
int i = 100;
int *ip1, *ip2;
ip1 = &i;
ip2 = ++ip1;
–ip1;
printf(“diff : %u\n”, ip2-ip1);
return 0;
}

 
 
 
 

5. What is a void pointer?

 
 
 
 

6. What is the output of this C code?
#include<stdio.h>
void main()
{
char sport[]= “sports”;
int x=1 , y;
y=x++ + ++x;
printf(“%c”,sport[++y]);
}

 
 
 
 

7. Comment on the following pointer declaration? [int *ptr, p;]

 
 
 
 

8. Which of the following is the correct way to declare a pointer to an array of 3 integer elements?

 
 
 
 

9. 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++);
}

 
 
 
 

10. 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;
}

 
 
 
 

Question 1 of 10

Share this