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 = 9, j = 10, k = 0; k = i & j; return 0; }
Ans: B
Question 2
/* Statement 1*/ int* fx () { int *i = new int; *i = 99; return i; } int main() { /* Statement 2*/ int* p = fx (); /* Statement 3*/ *p = 8; /* Statement 4*/ delete p; return 0; }
Ans: B
Question 3
int main() { int b; int a; /*Statement 1*/ b = 10; do { /*Statement 2*/ int x = 0; }while (b-- > 0); /*Statement 3*/ a = x; return 0; }
Ans: C
Question 4
#define PrintInt(expr) printf("%s : %d\n",#expr,(expr)) int max(int x, int y) { (x > y) ? return x : return y; } int main() { int a = 10, b = 20; PrintInt(a); PrintInt(b); PrintInt(max(a,b)); return 0; }
20
20
b : 20
max(a,b) : 10
b : 20
max(a,b) : 20
Ans: A
(x > y) ? return x : return y;doesnot compile. It can be corrected like this
return (x > y) ? x : y;The answer would be D then.
Question 5
void main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }
Ans: C
++*p means:"p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10. then it isincremented to 11. the value of ++*p is 11.
++*str1 means: "str1 is pointing to 'a'that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 isadded and result is subtracted from 32.i.e. (11+98-32)=77;
Question 6
int main () { int i = 0, j = 0; if (false) i++; j++; cout << "i is = " << i << ", j = " << j << endl; }
Ans: A
Question 7
int main () { /* line 1 */ int iAge; /* line 2 */ cout << "Enter you age ?"; /* line 3 */ cin >> iAge; /* line 4 */ cout << "Your age is: " << iAge << endl; }
Ans: B
Question 8
int GetBitCount(unsigned int x) { int count=0; while(x) { count++; x = x&(x-1); } return count; } int main() { int i = 3; printf ("%u", GetBitCount (i)); return 0; }
Ans: B
Question 9
#define SIZE 10 void size(int arr[SIZE]) { printf("size of array is:%d\n",sizeof(arr)); } int main() { int arr[SIZE]; size(arr); return 0; } NOTE: ASSUME THE SIZE OF AN int IS 32-bits, and the address is also 32-bits
Ans: C
Question 10
int main() { int a=3; const char* k = "Hello"; printf (&(k [a])); 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.