You are on page 1of 2

CAMPUS PLACEMENT COMMITTEE

MCA BATCH OF 2012


MOCK TEST
Date: 2nd Feb 2011 C Aptitude Time: 20 Mins

Predict the output of the code given, unless stated otherwise.

Q 1. main() {
char ch='A';
while(ch<='F'){
switch(ch){
case'A':case'B':case'C':case'D':ch++;continue;
case'E':case'F':ch++;
}
putchar(ch);
}}

Q 2.int a=1, b=2, c=3, *pointer;


pointer=&c; a=c/*pointer; b=c;
printf("a=%d b=%d",a,b);

Q 3. void fn(int *a, int *b){ int *t=a; a=b; b=t; }


main() {
int a=2, b=3;
fn(&a,&b);
printf(“%d %d”,a,b);
}

Q 4. main() {
int c=- -2; printf(“%d”, c);
}

Q 5.#define int char


main() {
int i = 65; printf(“sizeof(i)=%d”, sizeof(i));
}

Q 6. 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);
}

Q 7. main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

Q 8. main() { int i=5; printf("%d%d%d%d%d",i++,i--,++i,--i,i); }

Q 9. main( ) {
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch; printf(“%c”, *(char *)vp);
vp = &j; printf(“%d”,*(int *)vp);
vp = cp; printf(“%s”,(char *)vp + 3);
}
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 10.main() {
char *cptr,c;
void *vptr,v;
c=65; v=0; cptr=&c; vptr=&v;
printf("%c%d",c,v);
}

Q 11.main() {
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof str2,sizeof("abcd"));
}

Q 12.void main() {
while(1) {
if(printf("%d",printf("%d")))
break;
else
continue;
} }

Q 13.#define THIS
#define THAT
main() {
#ifdef THIS && THAT
printf(“Definitions are hard to digest”);
#else
printf(“Its easy”);
#endif
}

Q 14.main() {
char str1[] = {'s','o','m','e'};
char str2[] = {'s','o','m','e','\0'};
if(strcmp(str1,str2)) printf("Strings are not equal\n");
else printf(“Equal”);
}

Q 15.int size(int array[]){ return sizeof(array)/sizeof(int ); }


main() {
int arr[10];
printf(“Size= %d”, size(arr));
}

The GCC compiler has been used to test/execute the code, unless stated otherwise.
Page 2