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 main() { int i = 0; switch (i) { case 1: case 0: { return 0; } default: { switch (i + 8) { case 3: default: { return 6; } } } break; } return 0; }
Ans: C
Question 2
Ans: C
Question 3
int i = 40; int main () { do { printf ("%d", i++); }while (0, 1, 2, 3, 4, 5); return 0; }
Ans: BD
Question 4
int main() { while (1) { continue; } return 0; }
Ans: A
Question 5
int main() { short x = -(30*1000 + 2769); printf ("%d", x); return 0; }
Ans: C
Question 6
void main () { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }
Ans: A
++*p++. DO NOT write such a code.
NOTE: Many people give wrong answer - "++*p++ will be parse in the given order*p that is value at the location currently pointed by p will be taken++*p the retrieved value will be incrementedwhen ; is encountered the location will be incremented that is p++ will be executedHence, in the while loop initial value pointed by p is 'h', which is changed to 'i' byexecuting ++*p and pointer moves to point, 'a' which is similarly changed to 'b' and soon. Similarly blank space is converted to '!'. Thus, we obtain value in p becomes "ibj!gsjfoet" and since p reaches '\0' and p1 points to p thus p1doesnot print anything."
Question 7
void main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d----%d",*p,*q); }
Ans: D
Question 8
// class definition class CFile { // returns true if a file strFileName exists public: bool FileExists (const string& strFileName); // opens and reads the file strFileName public: void OpenAndRead (const string& strFileName); }; int main () { /* line 1 */ string strFile; /* line 2 */ cout << "Enter the name of the file to read: "; /* line 3 */ getline (cin, strFile); CFile obj; /* line 4 */ cout << "The data is: " << endl; obj.OpenAndRead (strFile); }
Ans: BD
Question 9
void main() { static char *s[ ] = { "black", "white", "yellow", "violet" }; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf("%s",*--*++p + 3); }
Ans: C
printf("%s",*(--(*(++p))) + 3);
Question 10
int main() { float f=0.0f; int i; for(i=0;i<10;i++) { f = f + 0.1f; } if(f == 1.0f) printf("f is 1.0 \n"); else printf("f is NOT 1.0\n"); return 0; }
Ans: B
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.