wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Programming Foundations Quiz

Total questions: 57

Worksheet time: 49mins

Name
Class
Date
1.

Which of the following is a feature introduced in C++ to support object-oriented programming?

a)

Pointer arithmetic

b)

Polymorphism

c)

Preprocessor directives

d)

Static typing

2.

True or False: A variable declared as const int x = 5; can be modified after initialization.

a)

True

b)

False

3.

What is the output of the following code? int x = 10; if (x > 5) cout << "High"; else cout << "Low";

a)

High

b)

Low

c)

Compile error

d)

No output

4.

Which of the following function declarations demonstrates valid function overloading?

a)

void print(int x); and int print(int x);

b)

void print(int x); and void print(float x);

c)

void print(int x); and void print(int y);

d)

void print(int x); and void print(int x, int y = 0);

5.

What is the output of this recursive function for n = 4! int sum(int n) { if (n <= 0) return 0; return n + sum(n - 1); }

a)

10

b)

6

c)

4

d)

Stack overflow

6.

True or False: A C++ class can have multiple constructors with different parameter lists.

a)

True

b)

False

7.

What is the value of x after executing: int x = 5; x += x++ * 2;?

a)

15

b)

11

c)

12

d)

Undefined

8.

What is the purpose of a constructor in a C++ class?

a)

To deallocate memory

b)

To initialize object data members

c)

To define class methods

d)

To handle exceptions

9.

Which operator is used to access members of a class through a pointer?

a)

.

b)

->

c)

::

d)

&

10.

Write a C++ recursive function to compute the nth Fibonacci number. Explain one advantage and one disadvantage of using recursion for this problem.

4 lines
11.

Define a C++ class Rectangle with private data members for length and width, and public methods to calculate area and perimeter. Show how to create an object and use these methods.

4 lines
12.

Write a C++ function using a loop to check if a number is prime. Explain how you would debug it if it incorrectly identifies 1 as prime.

4 lines
13.

What is the only function that all C++ programs must contain?

a)

start()

b)

system()

c)

main()

d)

program()

14.

Which command in C++ moves the text to the next line?

a)

\t

b)

\n

c)

\r

d)

\s

15.

C++ was developed by?

a)

Dennis Ritchie

b)

Bjarne Stroustrup

c)

James Gosling

d)

Guido van Rossum

16.

What is the extension of C++ programs?

a)

.c

b)

.css

c)

.cpp

d)

.jsp

17.

Which syntax is correct in printing an output in a C++ program?

a)

print<<"Good Day!";

b)

cout<<"Good Day!";

c)

printf<<"Good Day!";

d)

cout<<"Good"<<"Day!";

18.

Insertion operator (<<) is used with?

a)

cin

b)

cout

c)

both of the above

d)

main

19.

break() is used along which statements?

a)

while

b)

switch

c)

for-while

d)

if-then-else

20.

This is a code that has not yet been linked into a complete program.

a)

Source Code

b)

Assembly Code

c)

Object Code

d)

Machine Code

21.

The object code is produced in what program development phase?

a)

Preprocessing

b)

Compilation

c)

Linking

d)

Loading

e)

Executing

22.

What happens first when a C++ executable is run?

a)

The preprocessor converts the source code into an object code.

b)

The compiler converts the object code into an executable code.

c)

The linker links the object code with the missing functions needed to produce the executable code.

d)

The loader places the program in the memory

e)

The CPU executes the program

23.

By default, how are instructions executed by the CPU?

a)

One instruction at a time

b)

Several Instructions at a time

c)

All instructions in one time

d)

None of the above

24.

Single line comments are denoted by what symbol?

a)

//

b)

\

c)

/*

d)

*/

25.

Which of the following are ignored by the C++ compiler and the computer? (Check all that apply)

a)

Comments

b)

Blank lines

c)

Spaces

d)

Tab Spaces

e)

Preprocessing directives

26.

A preprocessing directive starts with what symbol?

a)

//

b)

#

c)

(

d)

{

27.

The library defined in the preprocessor directive must be enclosed by what symbols?

a)

{ }

b)

[ ]

c)

< >

d)

( )

28.

Blanks lines, spaces, and tab characters are called?

a)

Keywords

b)

White spaces

c)

Symbols

d)

Escape Sequences

29.

A code that is reserved by C++ for a specific use.

a)

Keyword

b)

White space

c)

Symbol

d)

Escape Sequence

30.

Which symbol starts a block of code?

a)

<

b)

(

c)

{

d)

[

31.

The words enclosed in double quotation marks are known as the following EXCEPT what?

a)

String

b)

Character String

c)

String Literal

d)

Stream

32.

The semicolon (;) is used to?

a)

Start a block of code

b)

Terminate a function

c)

Start a statement

d)

End a statement

33.

Which of the following is the scope resolution operator?

a)

<<

b)

>>

c)

::

d)

\

34.

Which of the following is the escape character operator?

a)

<<

b)

>>

c)

::

d)

\

35.

Which of the following is the input stream object?

a)

>>

b)

<<

c)

cin

d)

cout

36.

Which of the following is NOT a VALID identifier?

a)

X1

b)

_X1

c)

x1

d)

_1x

e)

1x

37.

NOT a VALID identifier? Which of the following are VALID identifiers?

a)

X1

b)

_X1

c)

x1

d)

_1x

e)

1x

38.

The process of creating a new variable without value

a)

declaration

b)

naming

c)

instantiation

d)

assigning

39.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

40.

What punctuation is used to signal the beginning and end of code blocks?

a)

{ }

b)

-> and <-

c)

BEGIN and END

d)

( and )

41.

Which of the following is a correct comment?

a)

*/ Comments /

b)

** Comment **

c)

/ Comment */

d)

{ Comment }

42.

After running the following code, what will be the value of x? y = 3; x = 5 * y;

a)

3

b)

5

c)

15

d)

0

43.

A programmer is:

a)

person who writes code and communicates instructions to a computer

b)

person who types

c)

person who studies computers

d)

error or mistake in your code

44.

What is the output of this program? int main() { cout << "Hi everybody"; return 0; }

a)

"Hi everybody"

b)

Hi everybody"

c)

Hi everybody

d)

"Hi everybody

45.

Which of the following is NOT a logical operator in C++ language?

a)

&

b)

&&

c)

||

d)

!

46.

Which of the following is NOT a comparison operator in C++ language?

a)

>

b)

<=

c)

=

d)

==

47.

If originally x=2, y=0, and z=1, what is the value of x, y, and z after executing the following code? if (x > y) y = x; else z = x;

a)

x=2 y=2 z=1

b)

x=0 y=2 z=0

c)

x=2 y=1 z=1

d)

x=2 y=0 z=1

48.

All variables must be declared before they are used.

a)

True

b)

False

49.

I liked the quiz?

4 lines
50.

Any suggestions?

4 lines
51.

True or False: A Boolean variable is declared with the bool keyword.

a)

True

b)

False

52.

True or False: The break statement can be used with while, for, and switch statements but not with if-then-else.

a)

True

b)

False

53.

True or False: A function in C++ can have default arguments only for the last parameters in the parameter list.

a)

True

b)

False

54.

Which of the following operators are used in C++? (Select all that apply)

a)

==

b)

+=

c)

**

d)

++

55.

Write a C++ program using a switch statement to classify a user-entered character as a vowel or consonant. Explain how you would debug it if it incorrectly classifies 'y' as a vowel.

4 lines
56.

Write a C++ function to overload the max function for integers and doubles. Explain the role of function overloading in this context.

4 lines
57.

Define a C++ class Student with private data members for name and roll number, and public methods to set and display them. Show how to create and use an object. Explain one benefit of encapsulation.

4 lines