Upload
sonal-maheshwari
View
215
Download
0
Embed Size (px)
Citation preview
8/6/2019 4th Feb 2011 - C
1/4
CAMPUS PLACEMENT COMMITTEEMCA BATCH OF 2012
MOCK TESTDate: 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
8/6/2019 4th Feb 2011 - C
2/4
CAMPUS PLACEMENT COMMITTEEMCA 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: Vers10nmain(){
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
8/6/2019 4th Feb 2011 - C
3/4
CAMPUS PLACEMENT COMMITTEEMCA BATCH OF 2012
MOCK TESTprintf("%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
8/6/2019 4th Feb 2011 - C
4/4
CAMPUS PLACEMENT COMMITTEEMCA BATCH OF 2012
MOCK TESTp = 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