ky thhuat lap trinh c

Upload: hunggheo

Post on 03-Mar-2016

220 views

Category:

Documents


0 download

DESCRIPTION

Ky Thhuat Lap Trinh C

TRANSCRIPT

!! Khi nim c bn

!! . If/else , switch( ) case, goto

1. What gets printed? Code:

void main(){int i = 3; if (!i) i++;i++;

if (i==3) i+=2; i+=2;printf("%d\n", i); getch();}

A. 7B. 5C. 6D. Another

2. What gets printed? Code:

void main(){int x; if(x=0)printf ("Value of x is 0");elseprintf ("Value of x is not 0"); getch();}

A. Value of x is 0B. Value of x is not 0C. Error

3. What gets printed? Code:

void main(){int i; for(i=0;i2 ? i++:i--);printf("%d",i); getch();}

A. -1B. 0C. Complier error

6. What output is? Code:

void main(){int i=10,j=20; if(i=20)printf(" Hello"); elseprintf(" Hi"); getch();}

A. HelloB. Hi

C. Complier error

7. What output is? Code:

void main(){int x=0,y=0; if(x==0||++y) printf(" x=%d",x);printf(" y=%d",y); getch();}

A. x=0 y=1B. x=0 y=0C. Error syntax

8. What output is? Code:

void main(){int i = 5, k; if (i == 0) goto label;label: printf("%d", i);printf("Hey"); getch();}

A. HeyB. 5C. 5HeyD. Complie error

9. What output is? Code:

void main(){printf("%d ", 1); goto l1; printf("%d ", 2); l1:goto l2; printf("%d ", 3);l2:printf("%d ", 4); getch();}

A. 1 4B. 1 2 3 4

C. Syntax errorD. Another

10. What output is? Code:

#include #include void foo();int main(){printf("%d ", 1); goto l1; printf("%d ", 2);}void foo(){l1: printf("3 ");}

A. Complie errorB. 3C. 1D. 1 3

11. What output is? Code:

#include #include int main(){int i = 0, j = 0; while (i < 2){l1: i++;while (j < 3){printf("loop\n"); goto l1;}}getch();}

A. loop loop loopB. Infinite loopC. Complie error

12. What output is? Code:

void main(){int i = 0, j = 0; while (l1: i < 2){i++;while (j < 3){printf("loop\n"); goto l1;}}getch();}

A. loop loopB. loop loop loop loopC. Complie errorD. Another

13. What output is? Code:

void main(){int a=15,b=10,c=5; if(a>b>c )printf("True");elseprintf("False"); getch();}

A. TrueB. FalseC. Complier ErrorD. Run time error

14. What output is? Code:

#include #include void main(){int i = 0; switch (i){case '0': printf("A"); break;

case '1': printf("B");

break;default: printf("ABC");}getch();}

A. AB. BC. ABC

15. What output is? Code:

#include #include "conio.h" void main(){int i = 3; switch (i){case 0+1: printf("A"); break;case 1+2: printf("B"); break;default: printf("ABC");}getch();}

A. AB. BC. ABC

16. What output is? Code:

#include #include #define A 0#define B 1 int main(){int i = 3; switch (i & 1){case A: printf("FALSE"); break;case B: printf("TRUE"); break;default: printf("Default");}

getch();

}

A. FALSEB. TRUEC. Default

17. What output is? Code:

#include #include int main(){int i;if (printf("0")) i = 3;elsei = 5;printf("%d", i); getch();}

A. 3B. 5C. 03D. 05

18. What output is? Code:

#include#include int main(){int a = 5; switch(a){default:a = 4;case 6:a--;case 5:a = a+1; case 1:a = a-1;}printf("%d \n", a); getch();}

A. 5B. 4

C. 3

19. What output is? Code:

#include #include int main(){int x = 3;if (x == 2); x = 0; if (x == 3) x++; else x += 2;printf("x = %d", x); getch();}

A. x = 2B. x = 6C. x = 0

20. What output is? Code:

#include #include int main(){int check = 20, arr[] = {10, 20, 30}; switch (check){case arr[0]: printf("A ");case arr[1]: printf("B");case arr[2]: printf("C");}getch();}

A. ABCB. BCC. BD. Complier Error

!! Vng lp for, do..while

1. What value is returned by function func? Code:

float func(){int r = 0, d = 0, i=0; for (i; i < 2; i++){r += 5 / d;}return r;}

A. 5B. 0C. ExceptionD. Another

2. What will be output when you will execute following c code? Code:

void main(){char s[ ]="man"; int i;for(i=0;s[ i ];i++)printf("%c%c%c%c\t",s[ i ],*(s+i),*(i+s),i[s]); getch();}

A. mmmm aaaa nnnnB. mmm aaa nnnC. mmmm aaa nnnD. Another

3. What will be output when you will execute following c code? Code:

void main(){int i = 0;char ch = 'A'; do{putchar (ch);}while(i++ < 5 || ++ch