0% found this document useful (0 votes)
211 views2 pages

C Aptitude 3

The document contains 25 coding questions with outputs or errors. It tests concepts like pointers, arrays, structures, functions, preprocessing, and more. The questions would need to be solved individually to determine the correct outputs or errors.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views2 pages

C Aptitude 3

The document contains 25 coding questions with outputs or errors. It tests concepts like pointers, arrays, structures, functions, preprocessing, and more. The questions would need to be solved individually to determine the correct outputs or errors.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Aptitude test-3

Predict the output or error(s) for the following:

1. main(){ clrscr(); }clrscr(); Answer:

2. enum colors {BLACK,BLUE,GREEN}


main(){ printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);} Answer:

3. void main(){ char far *farther,*farthest;


printf("%d..%d",sizeof(farther),sizeof(farthest)); }Answer:

4. main(){ int i=400,j=300; printf("%d..%d");}Answer:

5. main(){ char *p; p="Hello"; printf("%c\n",*&*p);}Answer:

6. main(){ int i=1; while (i<=5){ printf("%d",i);


if (i>2) goto here; i++;}}
fun(){ here: printf("PP");}Answer:

7. main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"};


int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t;
for (i=0;i<=4;i++) printf("%s",names[i]);}Answer:

8. void main(){ int i=5; printf("%d",i++ + ++i);}Answer:

9. void main(){ int i=5; printf("%d",i+++++i);}Answer:

10. #include<stdio.h>
main(){ int i=1,j=2; switch(i) {
case 1: printf("GOOD"); break;
case j: printf("BAD"); break; }}Answer:

11. main(){ int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here


}Answer:

12. #define f(g,g2) g##g2


main(){ int var12=100; printf("%d",f(var,12));}Answer:

13. main(){ int i=0; for(;i++;printf("%d",i)) ; printf("%d",i);}Answer:

1
14. #include<stdio.h>
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);}Answer:

15. #include<stdio.h>
main(){ struct xx{ int x=3; char name[]="hello"; };
struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x);
printf("%s",s->name); }Answer:

16. #include<stdio.h>
main(){ struct xx { int x; struct yy { char s; struct xx *p; };
struct yy *q;};}Answer:

17. main(){ extern int i; i=20; printf("%d",sizeof(i));}Answer:

18. main(){ printf("%d", out);} int out=100; Answer:

19. main(){ extern out; printf("%d", out);} int out=100; Answer:

20. main(){ show();}void show(){ printf("I'm the greatest");}Answer:

21. main( ){ int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};


printf(“%u %u %u %d \n”,a,*a,**a,***a);
printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }Answer:

22. main( ){ int a[ ] = {10,20,30,40,50},j,*p;


for(j=0; j<5; j++){printf(“%d” ,*a); a++; } p = a;
for(j=0; j<5; j++){printf(“%d ” ,*p); p++;}} Answer:

23. main( ){ static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4};


int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }Answer:

24. main( ){ char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j));
for (j=0; j<3; j++) printf(“%c” ,*(q+j));
for (j=0; j<3; j++) printf(“%s” ,(q+j));} Answer:

25. 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);}Answer:

You might also like