Multi Choice 1
Multi Choice 1
-2 Hours to complete this. I will collect them after the session, so that I can get an idea of which topics I need to go over as a refresher. You will be also be given a second copy. Please use this copy to make any notes / keep a copy for yourself. 1. What a. b. c. is an IDE? Internet Debugging Editor Integrated Development Environment Interdependent element
2. Put these stages of compilation in order:a. Link b. Compilation c. Execute d. Precompilation 3. At which stage are #include and #define identified:a. Precompilation b. Compilation c. Linking 4. Which of these commands would give you access to the printf function:a. include stdio.h; b. #include <stdio.h> c. #include conio.h; 5. How would you declare a constant of 5 called "MYCONST"? a. constant MYCONST = 5; b. int myconst = 5; c. #define MYCONST 5 6. How would declare two integers called "i" and "j"? a. int i, j; b. int i + j: c. int i int j; 7. Which of the following declarations could store the number 5.5? a. char num; b. int num; c. float num; 8. What a. b. c. is a variable? A place to store single items of data that cannot change A place to store a list of data A place to store a single item of data that can be overwritten
9. How would you display an integer variable 'i' starting with the text "Total: "? a. printf( 'Total: %i' i ); b. printf( "Total: %d", i ); c. printf( "Total: " + i ) 10. Which of these is NOT a valid name for a C variable: a. Hello There b. HELLO_THERE c. HelloThere
11. What value would be stored in an integer variable "i" as a result of the following calculation: int i, j; j=3; i = 4 + 2 * j / ( j - 1 ); a. 1 b. 7 c. 9 12. Which of the following would read a decimal number into a float variable 'f' from the keyboard? a. readf ( f ); b. scanf ( "%f", &f ); c. scanf ( "&f", f ); 13. Which of the following will NOT increase an integer variable "i" by 1? a. i++; b. i+=1; c. i=i+i; 14. Which of the following loops will NEVER exit (assuming a variable does not have a limit on how larger or small the number it holds can be)? a. int i=0; do { i++; } while (i < 10); b. int i=10; while (i<=10) { i--; } c. int i=10; do { i--; if (i==0) break; } while (1); 15. Which of the following conditions will cause the word "TRUE" to be displayed, given two variables: int i, j; i=3; j = 5; a. if ( (i=3) && (j<>i) ) printf("TRUE"); b. if ( (i== (j-2)) || ( i == j ) ) printf ("TRUE"); c. if ( ( i != j ) && ( (i-j) == 2 ) printf("TRUE"); 16. Which of the following for loops will display a count from 1 to 10, given an integer variable i has already been declared? a. for ( i == 0; i++; i<10) printf( "i is %d", i); b. for ( i == 1; i<10; i++); printf( "i is %d", i);
c. for ( i == 1; i<=10; i++) printf( "i is %d", i); 17. Which of the following commands would read a single character from the keyboard and place the result in a character variable 'ch' defined as: char ch; a. ch = getch(); b. printf( "%c", ch ); c. getkeyb ( ch ); 18. Which of the following would you use to declare a character array called str large enough to fit the word HELLO ? (without the question mark) a. char str[6] b. string str; c. char str[5] 19. Which of the following would you use to place a comment into your program? a. REM This is a comment b. /* This is a comment */ c. { This is a comment } 20. What number would be shown on the screen after the following lines of C are executed? char ch; int i; ch='G'; i = ch 'A'; printf( "Number: %d\n", i ); a. 6 b. 7 c. 8 21. How would you copy the name "Hello" to a character array (i.e. string) declared as follows:char str[10]; a. str = "Hello"; b. printf( str, "Hello" ); c. strcpy( str, "Hello" ); 22. Which of the following switch statements will show the correct days of the week, where 0=Sunday, 1=Monday and 2 = Tuesday (the others are ignored). The initial day value is held in the variable 'day'? (a)
switch ( day ) { case(0): printf("Sun"); break; case(1): printf("Mon"); break; default: printf("Tue"); break; }
(b)
switch ( day ) { case(0): printf("Sun"); case(1): printf("Mon"); case(2): printf("Tue"); break; }
(c)
switch ( day ) { case(0): printf("Sun"); break; case(1): printf("Mon"); break; case(2): printf("Tue"); }
23. How would you convert from a string to an integer number? The variables are defined as follows:char str[10]; int i; printf("Enter str: "); gets(str); a. i = atoi ( str ); b. scanf ( str, "%d", i ); c. sprintf ( str, "%s", i ); 24. Which of the following will keep asking for a key to be pressed until either "Y" or "N" is pressed, and will then continue with the program? char ch; a. do { printf("Y or N: "); ch=getche(ch); } while ( ch <> "Y") or ( ch <> "N" ); b. do { printf("Y or N: "); ch=getche(ch); } while ( ( ch == Y) || ( ch == N ) ); c. do { printf("Y or N: "); ch=getche(ch); } while ( ( ch != 'Y') && ( ch != 'N' ) ); 25. Which of the following programs will correctly add up a list of five numbers and show the total? int count, num, total; (a)
total = 0; for ( count=1; count<5; count++ ) { printf( "Num %2d: ", count ); scanf( "%d", num ); total += num; } printf( "Total is: %4d\n", total );
(b)
total = 0; for ( count=0; count<5; count++ ) { printf( "Num %2d: ", count ); scanf( "%d", num ); total = num; } printf( "Total is: %4d\n", total );
(c)
total = 0; for ( count=1; count<=5; count++ ) { printf( "Num %d: ", count ); scanf( "%d", num ); total += num; } printf( "Total is: %d\n", total );
26. Which of the following would you use to test if the variable 'i' contains 3, and if it is does display "YES" otherwise display "NO"? a. if ( i == 3 ) printf( "YES" ); else printf("NO"); b. if ( i == 3 ) printf( "NO" ); else printf("YES"); c. if ( i != 3 ) printf( "YES" ) else printf("NO"); 27. Which of the following three programs would you consider to be well indented? (a)
int i, j = 0; for (i=0; i<=5; i++) { printf("i:%d\n", i); for (i=0; i<=5; i++) { printf("j:%d\n", j); }
(b)
int i, j = 0; for (i=0; i<=5; i++) { printf("i:%d\n", i); for (i=0; i<=5; i++) { printf("j:%d\n", j);
(c)
int i, j = 0; for (i=0; i<=5; i++) { printf("i:%d\n", i); for (i=0; i<=5; i++) { printf("j:%d\n", j);
28. Which of the following three C code snippets WILL NOT read a date as three integers as follows: int day, month, year; a. printf("Enter date: "); scanf("%d/%2d/%2d", day, month, year); b. printf("Enter date: "); gets( day); gets( month); gets( year); c. printf("Enter date: "); scanf("%d", day); scanf("%d", month); scanf("%d", year); 29. Which of the following three methods will subtract a value of 2 from the variable 'i'? a. i+=-2; b. i--; c. i-=i-2; 30. Which command is used to skip the rest of a loop and carry on from the top of the loop again? a. break; b. resume; c. continue;