C Questions: Predict The Output or Error(s) For The Following
C Questions: Predict The Output or Error(s) For The Following
C Questions
printf("%d",++(*p));
2. 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]);
3. main()
float me = 1.1;
if(me==you)
else
-1-
Placement Cell
4. main()
{
printf("%d ",var--);
if(var)
main();
}
5. main()
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
6. main()
extern int i;
i=20;
printf("%d",i);
-2-
Placement Cell
7. main()
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
8. main()
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
9. main()
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
-3-
Placement Cell
break;
}
10. main()
printf("%x",-1<<4);
}
11. main()
display(string);
printf("%s",string);
12. main()
printf("c=%d", c);
main()
int i=65;
-4-
Placement Cell
printf("sizeof(i)=%d",sizeof(i));
14. main()
int i=10;
i=!i>14;
Printf ("i=%d",i);
15. #include<stdio.h>
main()
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
16. #include<stdio.h>
main()
int *p,*q;
-5-
Placement Cell
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
17. #include<stdio.h>
main()
struct xx
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
18. #include<stdio.h>
main()
struct xx
int x;
struct yy
char s;
-6-
Placement Cell
struct xx *p;
};
struct yy *q;
};
19. main()
printf("\nab");
printf("\bsi");
printf("\rha");
}
20. main()
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
main()
int i;
i = 64/square(4);
printf("%d",i);
22. main()
-7-
Placement Cell
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
#define a 10
main()
#define a 50
printf("%d",a);
}
main()
clrscr();
printf("%d\n",clrscr());
}
25. main()
printf("%p",main);
}
27) main()
-8-
Placement Cell
clrscr();
clrscr();
main()
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
30) main()
int i=400,j=300;
printf("%d..%d");
}
31) main()
char *p;
p="Hello";
-9-
Placement Cell
printf("%c\n",*&*p);
}
{
printf("%d",i);
if (i>2)
i++;
}
fun()
here:
printf("PP");
}
33) main()
int i;
t=names[3];
names[3]=names[4];
- 10 -
Placement Cell
names[4]=t;
}
}
printf("%d",i+++++i);
}
36) #include<stdio.h>
main()
int i=1,j=2;
switch(i)
{
break;
}
- 11 -
Placement Cell
}
37) main()
int i;
}
main()
int var12=100;
printf("%d",f(var,12));
}
39) main()
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
40) #include<stdio.h>
main()
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
- 12 -
Placement Cell
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
41) #include<stdio.h>
main()
struct xx
{
};
printf("%d",s->x);
printf("%s",s->name);
}
42) #include<stdio.h>
main()
struct xx
{
int x;
struct yy
{
- 13 -
Placement Cell
};
};
}
43) main()
extern int i;
i=20;
printf("%d",sizeof(i));
}
44) main()
printf("%d", out);
int out=100;
45) main()
extern out;
printf("%d", out);
46) main()
show();
- 14 -
Placement Cell
void show()
}
47) main( )
printf(“%u %u %u %d \n”,a,*a,**a,***a);
}
48) main( )
int a[ ] = {10,20,30,40,50},j,*p;
{
printf(“%d” ,*a);
a++;
}
p = a;
{
printf(“%d ” ,*p);
p++;
}
- 15 -
Placement Cell
}
49) main( )
int **ptr = p;
ptr++;
*ptr++;
*++ptr;
++*ptr;
}
50) main( )
char *q;
int j;
51) main( )
- 16 -
Placement Cell
void *vp;
int j = 20;
vp = &ch;
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
52) main ( )
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
53) main()
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
- 17 -
Placement Cell
{
printf(“%s\n”,x);
x++;
}
}
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
55) main()
{
+i;
}
56) What are the files which are automatically opened when a C file is executed?
a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);
58) main()
{
- 18 -
Placement Cell
}
;
60) main()
{
main();
}
61) main()
{
printf("%c%v",c,v);
}
62) main()
{
}
- 19 -
Placement Cell
63) main()
{
not=!2;
printf("%d",not);
}
main() {
if(NULL)
puts("NULL");
puts("TRUE");
else
puts("FALSE");
}
65) main()
{
}
66) main()
{
int y;
- 20 -
Placement Cell
else
}
main()
{
}
main()
{
{
{
printf("%d",i);
}
- 21 -
Placement Cell
}
printf("%d",i);
}
69) main()
{
{
}
70) main()
{
-i;
}
71) #include<stdio.h>
main()
{
float j;
j = ++i;
- 22 -
Placement Cell
}
72) #include<stdio.h>
main()
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}
73) #include<stdio.h>
main()
{
}
74) main()
printf("%d",i+++j);
}
- 23 -
Placement Cell
int i;
};
main()
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
{
int x;
int y;
};
main()
- 24 -
Placement Cell
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
78) main()
int i=_l_abc(10);
printf("%d\n",--i);
int _l_abc(int i)
return(i++);
}
79) main()
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
- 25 -
Placement Cell
80) main()
getc(c);
x=convert(c);
printf("%c",x);
convert(z)
return z-32;
getchar();
sum(argv[1],argv[2]);
sum(num1,num2)
int num1,num2;
return num1+num2;
- 26 -
Placement Cell
int one_d[]={1,2,3};
main()
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}
83) # include<stdio.h>
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
- 27 -
Placement Cell
ptr[2]();
}
85) #include<stdio.h>
main()
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}.
86) main()
int i =0;j=0;
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
87) main()
int i;
i = abc();
printf("%d",i);
abc()
- 28 -
Placement Cell
_AX = 1000;
}
88) int i;
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
}
89) main(){
if(a,b,x,y)
printf("hello");
}
90) main(){
unsigned int i;
for(i=1;i>-2;i--)
}
91) In the following pgm add a stmt in the function fun such that the address of
main(){
int * j;
- 29 -
Placement Cell
fun(&j);
}
int a =0;
}
92) What are the following notations of defining functions known as?
{
}
{
}
93) main()
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
- 30 -
Placement Cell
94) main(){
char a[100];
a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
abc(a);
abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}
95) func(a,b)
int a,b;
return( a= (a==b) );
main()
int process(),func();
process(pf,val1,val2)
int val1,val2;
- 31 -
Placement Cell
return((*pf) (val1,val2));
}
if(--i){
main();
}
}
return(ret);
}
- 32 -
Placement Cell
}
int i;
if(printf("%s\n",a))
else
- 33 -