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

C Aptitude 2

The document contains 25 coding problems with errors or outputs. The summary provides the high-level information: 1) The document poses 25 coding problems ranging from errors in pointer operations, type mismatches, undefined behaviors, macro replacements, and more. 2) For each problem, the expected error or output is asked. This serves as an aptitude test to evaluate skills in C programming and finding bugs. 3) Identifying and explaining the errors or outputs for each problem would demonstrate understanding of core C concepts like pointers, type conversions, precedence rules, scope of variables, and macro replacements.
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)
208 views2 pages

C Aptitude 2

The document contains 25 coding problems with errors or outputs. The summary provides the high-level information: 1) The document poses 25 coding problems ranging from errors in pointer operations, type mismatches, undefined behaviors, macro replacements, and more. 2) For each problem, the expected error or output is asked. This serves as an aptitude test to evaluate skills in C programming and finding bugs. 3) Identifying and explaining the errors or outputs for each problem would demonstrate understanding of core C concepts like pointers, type conversions, precedence rules, scope of variables, and macro replacements.
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-2

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

1. void main(){ int const * p=5; printf("%d",++(*p)); } Answer:

2. main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++)


printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); } Answer:

3. main() { float me = 1.1; double you = 1.1; if(me==you)


printf("I love U"); else printf("I hate U"); } Answer:

4. main(){ static int var = 5; printf("%d ",var--);


if(var) main(); } Answer:

5. main(){ int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c;


for(j=0;j<5;j++) { printf(" %d ",*c); ++q; }
for(j=0;j<5;j++){printf(" %d ",*p);++p; }}Answer:

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

7. main(){ int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++;


printf("%d %d %d %d %d",i,j,k,l,m); }Answer:

8. main(){ char *p; printf("%d %d ",sizeof(*p),sizeof(p));}Answer:

9. main(){ int i=3;


switch(i) {
default:printf("zero");
case 1: printf("one"); break;
case 2:printf("two"); break;
case 3: printf("three"); break; }}Answer :

10. main(){ printf("%x",-1<<4);}Answer:

11. main(){ char string[]="Hello World"; display(string);}


void display(char *string){printf("%s",string);} Answer:

12. main(){int c=- -2; printf("c=%d",c);}Answer:

13. #define int char main(){ int i=65;


printf("sizeof(i)=%d",sizeof(i));}Answer:

1
14. main(){int i=10; i=!i>14;
Printf ("i=%d",i);}Answer:

15. #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:

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

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

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

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


Answer:

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


Answer:

21. #define square(x) x*x


main() { int i; i = 64/square(4); printf("%d",i);}Answer:

22. main() { char *p="hai friends",*p1; p1=p;


while(*p!='\0') ++*p++; printf("%s %s",p,p1);}Answer:

23. #include <stdio.h>


#define a 10
main(){ #define a 50 printf("%d",a);}Answer:

24. #define clrscr() 100


main(){ clrscr(); printf("%d\n",clrscr());}Answer:

25. main(){ printf("%p",main);}Answer:

You might also like