MCQ CSaxvbnswers
MCQ CSaxvbnswers
printf(%d , x ) ; *y = 107; printf(%d , x ) ; printf(%d , *y ) ; Choose one answer. a. 46, 107, 107============================ b. 46 , 46 , 107 c. None of the above d. 46, 107, -453
Marks: 1 2) What will be the output after executing the following code? char buf[10]= wxyz; char s[] = "abcdefg"; strcpy(buf, s+5); printf(buf = %s , buf); Choose one answer. a. buf = fgyz b. None of the above c. buf = wxyzfg d. buf = fg========================================= Marks: 1 3) Which one of the following will read a character from the keyboard and w ill store it in the variable c? Choose one answer. a. getchar( &c ) b. c = getc(); c. c = getchar();=============================== d. c = getchar( stdin ); Marks: 1
4) How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers? Choose one answer. a. %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal not ation. b.================= %e expects a corresponding argument of type double; %f expe cts a corresponding argument of type float. c. %e displays an argument of type double with trailing zeros; %f never display s trailing zeros. d. %e always displays an argument of type double in engineering notation; %f al ways displays an argument of type double in decimal notation. Marks: 1 5) In terms of code generation, how do the two definitions of buf, both pre sented below, differ? char buf [] = "Hello world!"; char * buf = "Hello world!";
Choose one answer. a. The first definition is not legal because it does not indicate the size of t he array to be allocated; the second definition is legal. b. ================They do not differ -- they are functionally equivalent. c. The first definition does not allocate enough space for a terminating NUL-ch aracter, nor does it append one; the second definition does d. The first definition is not suitable for usage as an argument to a function call; the second definition is. Marks: 1 6) What function will read a specified number of elements from a file? Choose one answer. a. readfile() b. fread()============================= c. getline() d. fileread() 7 Marks: 1 The function below has a flaw that may result in a serious error during some inv ocations. Which one of the following describes the deficiency illustrated below? int fibonacci (int n) { switch \(n\) { default:
return (fibonacci(n - 1) + fibonacci(n - 2)); case 1: case 2: } return 1; } Choose one answer. a. A break statement should be inserted after each case. Fall-through is not des irable here. b. For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes. c. An error in the algorithm causes unbounded recursion for all values of n. d. Since the default case is given first, it will be executed before any case ma tching n. 8 Marks: 1 Which one of the following can replace the ???? in the code below to determine i f the end of a file has been reached?
FILE *f = fopen( fileName, "r" ); readData( f ); if( ???? ) { puts( "End of file was reached" ); } Choose one answer. a. f == NULL b. !f c. f == EOF d. feof( f )============================================================= 9 Marks: 1 How is a variable accessed from another file? Choose a. The b. The c. The d. The one answer. global variable global variable global variable global variable is is is is referenced referenced referenced referenced via via via via the the the the global specifier. auto specifier. pointer specifier. extern specifier.
10 Marks: 1
What will the below sample code produce when executed? void myFunc (int x) { if (x > 0) myFunc(--x); printf("%d, ", x); } int main() { myFunc(5); return 0; }
Choose one answer. a. 0, 1, 2, 3, 4, 5, b. 5, 4, 3, 2, 1, 0, c. 0, 0, 1, 2, 3, 4,================================================= d. 4, 3, 2, 1, 0, 0, Time Remaining You are logged in as 080432X RUSHDI (Logout) </PRE></BODY></HTML>