C Programming Questions and Answers
What will be the output of the following program :
#include<stdio.h>
main()
{
int a=555,b=*ptr,*ptr=&a;
printf("%d %d %d",++a,--b,*ptr++);
}
Answer : Option A
What will be the output of the following program :
#include<stdio.h>void main()
{
float val=5.75;
int *ptr=&val;
printf("%.2f %.2f",*(float *)ptr,val);
}
Answer : Option B
What will be the output of the following program :
#include<stdio.h>
main()
{
int a=5u,*b,**c,***d,****e;
b=&a;
c=&b;
d=&c;
e=&d;
printf("%u %u %u %u",*b-5,**c-11,***d-6,65535+****e);
}
Answer : Option B
What will be the output of the following program :
#include<stdio.h>void main()
{
int (*a)[5];
printf("%d %d",sizeof(*a),sizeof(a));
}
Answer : Option D
What will be output of following program?
#include<stdio.h>#include<string.h>int main()
{
int register a;
scanf("%d",&a); // say a = 10
printf("%d",a);
return0;
}
Answer : Option D
Explanation :
Register data type stores in CPU. So it has not any memory address. Hence we cannot write &a.
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
}
Answer : Option A
In which header file is the NULL macro defined?
Answer : Option C
Explanation :
The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.
What will be output of following program?
#include<stdio.h>#include<string.h>int main()
{
int a,b,c,d;
char *p = (char*)0;
int *q = (int*q)0;
float *r = (float*)0;
double *s = 0;
a = ( int)(p+1);
b = ( int)(q+1);
c = ( int)(r+1);
d = ( int)(s+1);
printf("%d %d %d %d",a,b,c,d);
return0;
}
Answer : Option B
Explanation :
Address + 1 = next address
What will be output of following program?
#include<stdio.h>#include<string.h>int main()
{
int a,b,c,d;
char *p = (char*)0;
int *q = (int*q)0;
float *r = (float*)0;
double *s = 0;
a = ( int)(p+1);
b = ( int)(q+1);
c = ( int)(r+1);
d = ( int)(s+1);
printf("%d %d %d %d",a,b,c,d);
return0;
}
Answer : Option B
Explanation :
Address + 1 = next address
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",++val,*ptr);
}
Answer : Option D