The document contains 30 code snippets with questions about the output of each snippet. The snippets cover a range of C programming concepts like data types, operators, functions, arrays, pointers, typedefs and macros.
2. 1. What will be output when you will execute
following c code?
#include<stdio.h>
int main(){
printf("%dt",sizeof(6.5));
printf("%dt",sizeof(90000));
printf("%d",sizeof('A'));
return 0;
}
3. 2.What will be output when you will execute following
c code?
#include<stdio.h>
int main(){
signed x;
unsigned y;
x = 10 +- 10u + 10u +- 10;
y = x;
if(x==y)
printf("%d %d",x,y);
else if(x!=y)
printf("%u %u",x,y);
return 0;
}
4. 3.What will be output when you will execute
following c code?
#include<stdio.h>
int main(){
double num=5.2;
int var=5;
printf("%dt",sizeof(!num));
printf("%dt",sizeof(var=15/2));
printf("%d",var);
return 0;
}
5. 4.What will be output when
you will execute following c code?
#include<stdio.h>
enum A{
x,y=5,
enum B{
p=10,q
}varp;
}varx;
int main(){
printf("%d%d",x,varp.q);
return 0;
}
7. 6.What will be the output of the following.
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,b=1,c=0,i;
clrscr();
printf("%dt%dt",a,b);
for(i=0;i<=10;i++)
{
c=a+b;
if(c<100)
{
printf("%dt",c);
}
a=b;
b=c;
}
getch();
}
8. 7.What will be the output of the following code.
#include<stdio.h>
#include<conio.h>
void main()
{
int uabs(int), x;
clrscr();
printf(“enter a negative value:”);
scanf(“%d”, x);
x=uabs(x);
printf(“X=%d”, x);
return 0;
}
uabs(int y)
{
if(y<0)
return(y*-1);
else
return(y);
}
9. 8.What will be the content of 'file.c' after executing the
following program?
#include<stdio.h>
int main()
{
FILE *fp1, *fp2;
fp1=fopen("file.c", "w");
fp2=fopen("file.c", "w");
fputc('A', fp1);
fputc('B', fp2);
fclose(fp1);
fclose(fp2);
return 0; }
10. 9.What is the output of the
following program?
void main()
{
static int i=i++, j=j++, k=k++;
printf(“i = %d j = %d k = %d”, i, j, k);
}
11. 10.What is the output of the
following program?
main()
{
unsigned int i=10;
while(i-->=0)
printf(“%u ”,i);
}
12. 11.What is the output of the
following program?
#include<conio.h>
main()
{
int x,y=2,z,a;
if(x=y%2) z=2;
a=2;
printf(“%d %d”,z,x);
}
13. 12.What is the output of the
following program?
main()
{
int a[10];
printf(“%d”,*a+1-*a+3);
}
14. 13. What is the output of the
following program?
#define prod(a,b) a*b
main()
{
int x=3,y=4;
printf(“%d”,prod(x+2,y-1));
}
15. 14.What is the output of the
following program?
main()
{
unsigned int i=65000;
while(i++!=0);
printf("%d",i);
}
16. 15. What is the output of the
following program?
main()
{
float f=5,g=10;
enum{i=10,j=20,k=50};
printf(“%dn”,++k);
printf(“%fn”,f<<2);
printf(“%lfn”,f%g);
printf(“%lfn”,fmod(f,g));
}
17. 16. What is the output of the
following program?
main()
{
signed char i=0;
for(;i>=0;i++) ;
printf(“%dn”,i);
}
18. 17. What is the output of the
following program?
main()
{
unsigned char i=0;
for(;i>=0;i++) ;
printf(“%dn”,i);
}
19. 18.What is the output of the
following program?
main()
{
char *p = “ayqm”;
printf(“%c”,++*(p++));
}
21. 20.What is the output of the
following program?
main()
{
char str1[] = {‘s’,‘o’,‘m’,‘e’};
char str2[] = {‘s’,‘o’,‘m’,‘e’,‘0’};
while (strcmp(str1,str2))
printf(“Strings are not equaln”);
}
22. 21. What is the output of the
following program?
void main()
{
static int i;
while(i<=10)
(i>2)?i++:i--;
printf(“%d”, i);
}
23. 22.What is the output of the
following program?
main()
{
register int a=2;
printf(“Address of a = %d”,&a);
printf(“Value of a = %d”,a);
}
24. 23. What is the output of the
following program?
main()
{
float i=1.5;
switch(i)
{
case 1: printf(“1”);
case 2: printf(“2”);
default : printf(“0”);
}
}
25. 24.What is the output of the
following program?
main()
{
extern i;
printf(“%dn”,i);
{
int i=20;
printf(“%dn”,i);
}
}
26. 25.What is the output of the
following program?
main()
{
int i = 257;
int *iPtr = &i;
printf(“%d %d”, *((char*)iPtr), *((char*)iPtr+1));
}
27. 26. What is the output of the
following program?
main()
{
char a[4]=“HELLO”;
printf(“%s”,a);
}
28. 27.What is the output of the
following program?
void main()
{
int const * p=5;
printf("%d",++(*p));
}
29. 28.What is the output of the
following program?
main()
{
char s[ ]=“man”;
int i;
for(i=0;s[ i ];i++)
printf(“n%c%c%c%c”,s[ i ],*(s+i),*(i+s),i[s]);
}
30. 29.What is the output of the
following program?
main()
{
char *p;
printf(“%d %d ”,sizeof(*p),sizeof(p));
}
31. 30. What is the output of the
following program?
#define int char
main()
{
int i=65;
printf(“sizeof(i)=%d”,sizeof(i));
}