This quiz is a past event on Twitter. Twitter Quiz is an innovative brain child of Interview Mantra. It is a short quiz of 10 questions. This quiz was on C Language. Read more about Interview Mantra Twitter Quiz>
The Quiz questions, answers and their explanations have been consolidated as a blog post for your convenience.
-
Question1:
Declare an array of 3 function pointers, where each function receives two integers and returns float.Answer: float (*fn[3])(int, int);
-
Question2:
Global variables have program scope (True / False)?Answer: True
-
Question3:
Size of an int variable in C is a) 2 bytes b) 4 bytes c) machine dependent (Choose one answer)Answer: c) machine dependent
-
Question4:
getchar() function does not require a return key to record. (True / False)?Answer: a) True.
getchar() returns the character entered. It returns EOF in case of an error. It is recommended to use getchar instead of scanf. Using getchar() function in C, continuous stream of characters can be recorded without use of the return key. -
Question5:
break and continue statements are associated with the nearest loop in which they are present. (True / False)?Answer: True
Consider a code snippet -while(1){ if(i<5){ break; } }break statement is associated with the ‘while’ loop and not the ‘if’. break and continue statements are always associated only with the nearest loop in which they are present.
-
Question6:
static keyword limits the scope of global variables and functions to file scope (True / False)?Answer: True
File scope in C means that the variable or function is visible or accessible inside a file and not among other files in same program. A C program may contain multiple source files. So, file scope is not same as program scope.A program in C comprises of all the source files, header files and libraries involved. Scope means visibility to the compiler. Default scope of global variables and functions is program scope. It is limited to file scope when static keyword is prefixed.
-
Question7:
Which of the following header files is to be included to access function: int atoi(char *s);
a) stdlib.h b) ctype.h c) math.hAnswer: b) ctype.h
ctype.h declares some very useful character manipulation functions such as isdigit, isalpha, islower, isupper, tolower, toupper. Read more about ctype.h, a C standard library header file. -
Question8:
The function isdigit(9); returns non-zero? (True / False) ?Answer: b)False
Note that in C, 0 is not same as ’0′. 0 is an integer constant where as ’0′ is a character constant that equals ASCII value of 0. isdigit function returns non-zero, only if the input lies between ’0′ and ’9′. Else returns 0. -
Question9:
In pass by value, changes made to arguments in the called function have no effect on the values of those in the calling function. a)True or b)False?Answer: a)True
In Pass by value, a copy of arguments is sent to the called function. So changes to them has no effect on the actual arguments. -
Question10:
A switch statement can be input with a pointer expression and matched against pointer case values. (True / False) ?Answer: False
Switch statement can take only char or int as input. It does not entertain pointers or non-integer expressions as inputs or cases.