Sie sind auf Seite 1von 13

TEST YOUR SKILLS IN TURBO C Predict output of following programs 1. #include<stdio.

h> void main() { char src[20]="hello world",dest1[20],dest2[20],*s=src,*d1,*d2; int i=0,j; while(i++,*s++); for(j=i--,s=src,d1=dest1,d2=dest2;*d1++=*s++,*d2++=src[--i];); dest2[--j]='\0'; printf("%.*s %.5s",5,dest1,dest2); } Options are: a.illegal operation on pointers b.Lvalue required c.Non-portable pointer conversion d.none of these 2. #include<stdio.h> void main() { int i=-10; for(;i;i=-1,printf("%d%m",i=i+2),--i); } Options are: a.Expression Syntax error b.unpredictable output c.Too many parameters in for loop d.none of these

3.

#include<stdio.h> #define fibo(count) for(i=0;i<count;arr[i++]=num3)\ num3=num1+num2;\ num1=num2;\ num2=num3;\ } int count,num1=1,num2=1,num3,arr[100]; int i=0; void main() { static int arr[100]; fibo(3); printf("%d",arr[2]); }

{\

Options are: a.0 b.error:Too many declarations of arr[] c.5 d.Macro substitution error 4. #include<stdio.h> #define test(num) printf("%.*s",2,str[num%2]); char *str[2]={"even","odd"}; void main() { test(5); }

Options are: a.compilation error b.Run time error c.odd d.none of these

5. #include<stdio.h> #define fact(num) for(i=1,f=1;i<=num;f*=i++) int f; int i; void main() { int f=0; fact(3); printf("%d",f); }

Options are: a.0 b.6 c.Linking error d.none of these

6. #include<stdio.h> static int i; void main() { printf("%d",i+++++i); }

Options are: a.3 b.2 c.1 d.none of these 7. #include<stdio.h> #define test1(a,c,d,b) a##b##c##d

#define test2 test1(m,i,n,a) void test2() { printf("%-4s","test"); }

Options are: a.Linking error:main not found b.compilation error c.unpredictable output d.none of these

8. #include <stdio.h> int main() { int i=4; printf("%d %d %d ",i,(i=14,18,28),i); printf(" %d ",i); }

Options are: a.4 14 14 14 b.4 28 28 28 c.14 28 4 14 d.error 9. #include<stdio.h> int (*test1)(int); int test2(int); void main() { test1=test2; test1(2); } int test2(int n)

{ printf("%.*d %.*3d",3,n,n); } Options are: a.Non portable pointer conversion b.Null pointer assignment c.illegal operation on pointers d.none of these 10. #include<stdio.h> extern int i; void main() { { static int i=3; printf("%d ",i); } { auto int i=2; printf("%d ",i); } { register int i=1; printf("%d ",i); } printf("%d",i); } Options are: a.Too many declarations of variable i b.3 2 1 0 c.3 2 1 1 d.linking error 11. #include<stdio.h>

void main() { char *str1=NULL,*str2='\0',*str3; char ch; printf("%c %c \n",*str1,*str2); printf("%d %d ",sizeof(NULL),sizeof('\0')); printf("%d %d %d",sizeof('c'),sizeof('h'),sizeof('ch'));; } Options are: a.Non-poratable pointer conversion b. 21112 c.unpredictable output d. 22222 12. #include<stdio.h> int main(){ int i=9.9; printf("c is a "); if("you"=="you") printf("high level "); else if(i==9.9) printf("middle level"); else if(printf("%c\b",NULL)==0) printf("low level"); printf("language"); } Options are: a.c is a high level language b.c is a middle level language c.c is a low level language d.c is a language 13. #include<stdio.h> static int i;

void main() { printf("%d",i++ + ++i); } Options are a.Expression syntax error b.1 c.2 d.segmentation fault 14. #include<stdio.h> int main() { char ch='k'; static int i; switch(ch) { if(i==0) i++; default: i++; case 'k': case 'K': case 'm': i++; break; i=(i==3)?100:200; } printf("%2.*d",3,i); }

Options are: a.100 b.error:Misplaced if statement c.3 d.001 15.

#include <stdio.h> int main() { int i=3,j=4; printf("%d %ch",(++i,i==j,i=j)?(i=j):(i!=j),' '); }

Options are: a.compilation error b.unpredictable output c.4 d.none of these

16. #include <stdio.h> void main() { char src[10]="test",*dest=src; int i=-1; while(*dest++,i++); printf("%d ",i); while(i++,*dest++); printf("%d",i); } Options are: a.Too many parameters in while loop b.Lvalue required c.illegal pointer operation d.none of these

17. #include<stdio.h> int main()

{ int *x; x=0x200; *x=10; printf("%X %d",x,*x); } Options are: 1.illegal address assignment 2.Non-portable pointer arithmetic 3.unpredictable result 4.200 10 18. #include<stdio.h> int main() { int i=-100; printf("%x",i); } Options are: a.64 b.ff9c c.error:invalid hex conversion d.0x64 19. #include<stdio.h> int main() { int i=020; printf("%x %d",i,i); }

Options are: a.14 20 b.14 16

c.10 16 d.14 020 20. #include<stdio.h> int main() { printf("'\b%d\b'",printf("%d",putchar(NULL))); } Options are: a.Expression syntax error b.Linking error c.no output d.none of these 21. #include<stdio.h> void main() { int i=0,j=0; for(;j<printf("%d",i++);printf("%d",j++)); }

Options are: a.infinite loop b.001 c.error 4.no output 22. #include<stdio.h> int main() { int s=0,*p=&s; printf("%d %d %d",s,*p++,(*p)++);

Options are: a.0 0 1 b.illegal pointer operation c.Lvalue required d.1 1 0 23. #include<stdio.h> int main() { int s=0,*p=&s,**q=&p; printf("%d %d %d",s++,(*p)++,(**q)--); }

Options are: a.0 0 1 b.0 1 1 c.0 -1 0 d.error 24. #include<stdio.h> int main() { static int i; printf("%x",~(++i++)); } Options are: a.fffe b.0x01 c.FFFE d.none of these

25. #include<stdio.h> enum{false,true}; void test() { printf("%d", check()); } int check() { return main(1,0); } int main(int test,int check) { printf(" test "); return true; } #pragma startup test Options are: a.compilation error b.linking error c.unpredictable output d.none of these

1.d 2.d 3.c 4.d 5.b 6.d

ANSWER o/p:hello dlrow o/p:1%m o/p:5 o/p:od o/p:6 error:Lvalue required

7.d o/p:test 8.c o/p:14 28 4 14 9.d o/p:002 %.*3d 10.d linking error 11.d o/p:2 2 2 2 2 12.d o/p:c is a language 13.c o/p:2 14.d o/p:001 15.d o/p:4 h 16.d o/p:1 4 17.d o/p:200 10 18.b o/p:ff9c 19.c o/p:10 16 20.d o/p:0 21.b o/p:001 22.d o/p:1 1 0 23.c o/p:0 -1 0 24.d error:Lvalue required 25.d o/p:test 1 test

Das könnte Ihnen auch gefallen