Aptitude test-4
Predict the output or error(s) for the following
1) main ( ){ static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p;
printf(“%s”,*--*++p + 3);}Answer:
2) main(){ int i, n; char *x = “girl”; n = strlen(x); *x = x[n];
for(i=0; i<n; ++i){printf(“%s\n”,x);x++; } }Answer:
3) int i,j; for(i=0;i<=10;i++){ j+=5;assert(i<5); }Answer:
4) main(){int i=-1; +i;printf("i = %d, +i = %d \n",i,+i); }Answer:
5) What are the files which are automatically opened when a C file is executed?
Answer:
6) what will be the position of the file marker?
a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);Answer :
7) main(){char name[10],s[12]; scanf(" \"%[^\"]\"",s);}
How scanf will execute? Answer:
8) What is the problem with the following code segment?
while ((fgets(receiving array,50,file_ptr)) != EOF);Answer:
9) main(){main();}Answer:
10) main(){char *cptr,c; void *vptr,v; c=10; v=0;
cptr=&c; vptr=&v; printf("%c%v",c,v);}Answer:
11) main(){char *str1="abcd"; char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));}Answer:
12) main(){char not; not=!2; printf("%d",not);}Answer:
13) #define FALSE –1 #define TRUE 1 #define NULL 0
main(){ if(NULL) puts("NULL"); else if(FALSE) puts("TRUE");
else puts("FALSE");}Answer:
1
14) main(){int k=1;printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");}
Answer:
15) main(){int y; scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year");
else printf("%d is not a leap year");}Answer:
16) #define max 5 #define int arr1[max]
main(){ typedef char arr2[max];arr1 list={0,1,2,3,4};arr2 name="name";
printf("%d %s",list[0],name); }Answer:
17) int i=10; main(){ extern int i;{int i=20;{ const volatile unsigned i=30;
printf("%d",i); } printf("%d",i);}printf("%d",i);}Answer:
18) main(){ int *j;{int i=10; j=&i;}printf("%d",*j);}Answer:
19) main(){int i=-1; -i; printf("i = %d, -i = %d \n",i,-i);}Answer:
20) #include<stdio.h>
main(){const int i=4; float j; j = ++i; printf("%d %f", i,++j);}Answer:
21) #include<stdio.h>
main(){ int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q;
p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q);}Answer:
22) #include<stdio.h>
main(){ register i=5; char j[]= "hello"; printf("%s %d",j,i);}Answer:
23) main(){ int i=5,j=6,z; printf("%d",i+++j);}Answer:
24) struct aaa{struct aaa *prev; int i; struct aaa *next;};
main(){ struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;[Link]=&jkl;
[Link]=&def; def.i=1;[Link]=&abc;[Link]=&ghi;
ghi.i=2;[Link]=&def; [Link]=&jkl; jkl.i=3;[Link]=&ghi;[Link]=&abc;
x=[Link]->next->prev->next->i; printf("%d",x);}Answer:
25) struct point{int x; int y; };
struct point origin,*pp;
main(){pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);} Answer: