You are on page 1of 4

CAMPUS PLACEMENT COMMITTEE MCA BATCH OF 2012 MOCK TEST

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

CAMPUS PLACEMENT COMMITTEE MCA BATCH OF 2012 MOCK TEST


Q 4.
int main() { int a[0]={0,1,2,3}; a[-1]=2; printf("%d %d %d %d %d", sizeof(a),a[1],sizeof(a),a[1],sizeof(a[2]),a[3],a[1]); return 0; } Q 5.

Input is: This question is not easy!!


main() { char arr[50]; scanf("%[^\n]",arr); printf("%10.5s",arr); printf("\n%-10.5s",arr); printf("%10.-5s",arr); }

Q 6.Input is: Vers10n


main() { int i; scanf("%*s%n",&i); printf("%d",i); }

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

CAMPUS PLACEMENT COMMITTEE MCA BATCH OF 2012 MOCK TEST


printf("%s %d","All the best",i); }

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

CAMPUS PLACEMENT COMMITTEE MCA BATCH OF 2012 MOCK TEST


p = strtok (str, " "); if (p!=NULL) { ptr [ 0 ] = p; while (1) { p = strtok (NULL, " "); if (p == NULL) break; else { ptr [i]=p; } } } for (j = 0; j<i; j++) printf ("\n%s", ptr [j]); }

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

You might also like