Quiz Questions
Each question has four choices. More than one options can be correct. When you have finished the quiz, click the button at the end of the questions to view the result, and the solutions and answers.
Correct Answers: | |
Wrong Answers: | |
Unattempted: |
Question 1
int a = 0; int increment() { a++; return a; } int main(void) { a = increment (); cout << a << endl; return 0; }What is the output of the above program ?
Ans: D
Question 2
#define int char void main() { int i=65; // assume the size of an int = 4 and size of a char = 1 printf("sizeof(i)=%d",sizeof(i)); }
Ans: B
Question 3
int main() { int a=10; printf("%d %d %d", a, a++, ++a); return 0; }
Ans: D
Question 4
for (i = 0; i < 10; i++) { }
Ans: A
Question 5
#define F abc #define B def #define FB(arg) #arg #define FB1(arg) FB(arg) int main() { printf ("%s\n", FB(F B)); printf ("%s\n",FB1(F B)); return 0; }
FB1
abc def
abc
Ans: A
printf ("%s\n", FB(F B)); printf ("%s\n",FB1(F B));Change to
printf ("%s\n", "F B"); printf ("%s\n",FB(F B));the second printf further changes as follows
===> printf ("%s\n",FB(abc def)); ===> printf ("%s\n","abc def");
Question 6
int main () { int i = 9; if (i - 9) { /* Line 1 */ cout << "Inside first 'if'" << endl; } if (i + 9) { /* Line 2 */ cout << "Inside second 'if'" << endl; } }
Ans: B
Question 7
void main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }
Ans: A
Explanation :In third line, when the function display is encountered,a C-compiler doesn't know anything about the functiondisplay. It assumes the arguments and return types tobe integers, (which is the default type). When it sees theactual function display, the arguments and typecontradicts with what it has assumed previously. Hencea compile time error occurs. A C++ compiler also gives error: Undefined identifier
Question 8
void main() { int a = -12; a= a >> 3; printf("%d", a); }
Ans: D
The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 / 2E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined.
Question 9
void main() { int i=5; printf("%d",i+++++i); }
Ans: A
i++ ++ + iwhich is an illegal combination ofoperators.
NOTE: The following would be OK syntax wise -
i+++i; Is parsed as: i++ + i;But please be cautious because it would be undefined behavior because of sequence points.
Question 10
void main() { printf("\nab"); printf("\bsi"); printf("\rha"); }
Ans: A
My C/C++ Videos on Youtube
Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.