Professional Documents
Culture Documents
Date: 04.02.2011 C Aptitude Time: 20 mins Write the output for the following code snippets unless stated otherwise.
Q 1.
typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }
Q 2.
main() { char p[]="String"; int x=0; if(p=="String") { printf("pass 1"); if(p[sizeof(p)-2]=='g') printf("pass 2"); else printf("fail 2"); } else { printf("fail 1"); if(p[sizeof(p)-2]=='g') printf("pass 2"); else printf("fail 2"); } }
Q 3.
main() { char strp[] = "Never ever say no"; char *chp, c='e'; int i,j; chp = strrchr(strp, c); printf("%c\n\n",chp); i = chp-strp; for(j=0;j<=i;j++) printf("%c",strp[j]); }
The GCC compiler has been used to test/execute the code, unless stated otherwise. Page 1
Q 7.
main() { printf("MCA"); printf("\a\b\c\\0CD"); printf("\n\0NITT"); printf("WEL\rCOME"); }
Q 8.
main() { enum tag{abc=1,bcd=4,efg,xyz=-7}; printf("%d %d %d",efg,sizeof(bcd),sizeof(enum tag)); }
Q 9.
main(void) { int i=8; printf("Well done.\n%n",&i); The GCC compiler has been used to test/execute the code, unless stated otherwise. Page 2
Q 10.
#define ONE 4 #define TWO 3 #define THREE 5.4 main() { int i=4; switch(i) { case ONE: i++; case TWO: i+=2; default : i=2; } printf("%d",i); }
Q 11.
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); } };
Q 12.
main() { struct xx { char name[]="hello"; }; struct xx *s; printf("%s",s->name); }
Q 13.
main ( ) { char str [ ] = "This is a test"; char *ptr [10]; char *p; int i = 1, j; The GCC compiler has been used to test/execute the code, unless stated otherwise. Page 2
Q 14.
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); }
Q 15.
char *f() { char *s=malloc(8); strcpy(s,"goodbye"); } main() { char *f(); printf("%c",*f()='A'); }
The GCC compiler has been used to test/execute the code, unless stated otherwise. Page 2