Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : break and continue - 2Next Topic : pointer - 2

This section on C interview questions, tricky questions, and puzzles focuses on “pointer”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. Here is a listing of C questions and puzzles on “pointer” along with answers and/or explanations.

Q1: What will be the output of the C program?

#include<stdio.h>
int main()
{	int i=3;
	int *j;
	 j=&i;
	*j+=1;
	printf("%d ",i);
	return 0;
}
a)  3
b)  1
c)  4
d)  Garbaze
Correct Answer : c
Explanation : *j+=1 is solved as *j=*j+1, so it will change the value of i, because j means &i , and *j means i.
Learn pointer in deep


Q2: Which symbol is used to declare pointer?
a)  *
b)  &
c)  Both * and &
d)  None of these
Correct Answer : a
Explanation : Syntax for pointer declaration is
datatype *pointername;
e.g.
int *p;


Q3: What will be the size of p on turbo c?
float *p;
a)  2 byte
b)  4 bytes
c)  1 byte
d)  None of these
Correct Answer : a
Explanation : In c, addresses are always integer, so any pointer, whether is pointer to int or pointer to double or pointer to float, will have size equal to the size of int.


Q4: What will happen when we compile and run the following c code snippet?
#include<stdio.h>
int main()
{	const int a = 5;
	const int *ptr;
	ptr = &a;
	*ptr = 10;
	printf("%d", a);
	return 0;
}
a)  10
b)  5
c)  Compile time error
d)  Runtime error
Correct Answer : c
Explanation : const int *ptr; is a pointer to constant, it means we can not change the value of variable by using this pointer. const int *ptr declares ptr a pointer to const int type. You can modify ptr itself but the object pointed to by ptr shall not be modified.
Watch Solution video


Q5: What will be the output of the C program?
#include<stdio.h>
int main()
{      int a = 10;
	int *ptr;
	ptr = &a;
	ptr++;
	printf("%d ",*ptr);
	return 0;
}
a)  Syntax Error
b)  Runtime Error
c)  Garbaze Value
d)  11
Correct Answer : c
Explanation : Here ptr is the pointer variable which holds the address of another variable called a. When ptr is incremented, the address stored in ptr is incremented. As a result some garbage value will be displayed as we had not initialized anything to the address next to the address of the variable a.
Watch solution video


Previous Topic : break and continue - 2Next Topic : pointer - 2