C++ General Quiz 2

General quiz that can be taken as a self test to enhance your understanding for purposes of an interview or examination.

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

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.


Your Score
Correct Answers:
Wrong Answers:
Unattempted:

Q 1. What is '&' doing in the following code ?
int main()
{
int i = 9, j = 10, k = 0;
k = i & j;
return 0;
}
A. Multiplying value of i by address of j.
B. Performing a bitwise logical AND between i and j.
C. Performing a logical AND between i and j.
D. Multiplying j by address of i.
  A - B - C - D
Soln. Ans: b
Evaluation:

Q 2. What is '&' doing in the following code ?
int main()
{
int i = 9, j = 10, *k = 0;
k = i * (& j);
return 0;
}
A. Multiplying value of i by address of j.
B. Performing a bitwise logical AND between i and j.
C. Performing a logical AND between i and j.
D. Multiplying j by address of i.
  A - B - C - D
Soln. Ans: a
Evaluation:

Q 3. What is '*' doing in the following code ?
int main()
{
int i = 9, j = 10;
int *k;
return 0;
}
A. Multiplying value of k with int.
B. The usage is incorrect as per C-Standard.
C. declaring an int* variable identifier k.
D. Bitwise XOR operation.
  A - B - C - D
Soln. Ans: c
Evaluation:

Q 4. If you donot specify an entry-point in a C executable project, but otherwise commit no syntax errors -
A. The program compiles and links correctly
B. The program doesnot compile
C. The program compiles correctly but doesnot link
D. The program neither compiles nor links
  A - B - C - D
Soln. Ans: c
- the program compiles because no syntax errors, but will not link
Evaluation:

Q 5. What is the value of i [4] in the following code -
int main ()
{
int i [20] = {0};
}
A. 0
B. un-known or garbage
C. 20
D. 4
  A - B - C - D
Soln. Ans: a
- zeros in all locations
Evaluation:

Q 6. What is the value of i [4] in the following code -
int main ()
{
int i [20] = {20};
....
}
A. 0
B. un-known or garbage
C. 20
D. 4
  A - B - C - D
Soln. Ans: a
- i [0] is 20 and all others contain zeroes
Evaluation:

Q 7. How many times does the following loop execute ?
for (i = 0; i < 10; i) 
{

}
A. 10 times
B. for ever
C. 9 times
D. 11 times
  A - B - C - D
Soln. Ans: b
Evaluation:

Q 8. What is the value of 4 [i] in the following code -
int main ()
{
int i [20] = {20};
...
}
[NOTE: This question is different from 16 above]
A. 0
B. un-known or garbage
C. 20
D. 4
  A - B - C - D
Soln. Ans: a
4 [i] is same as i [4] because i [4] = *(i + 4), which is same as *(4 + i) ie, 4 [i]
Evaluation:

Q 9. What is the value of i in the following code
int i = 20 % 5
A. 4
B. 0
C. 5
D. 100
  A - B - C - D
Soln. Ans: b
Evaluation:

Q 10. What is pointer arithmetic -
A. Operations on two addresses
B. Operations on two values
C. Operations on an address and an integer
D. All of the above are correct
  A - B - C - D
Soln. Ans: c
Evaluation:

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.