Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Programming Quiz-Basics

Total questions: 35

Worksheet time: 20mins

Name
Class
Date
1.

C++ is a:

a)

Procedure-oriented language

b)

Object-oriented language

c)

Assembly language

d)

Markup language

2.

Which of the following is the correct file extension for C++?

a)

.c

b)

.java

c)

.cpp

d)

.py

3.

Which symbol is used to end a statement in C++?

a)

:

b)

.

c)

;

d)

,

4.

Which header file is required for cout and cin?

4 lines
5.

Which keyword is used to define a constant in C++?

a)

var

b)

let

c)

const

d)

define

6.

Which of the following is used to display output in C++?

a)

cin

b)

printf

c)

cout

d)

scanf

7.

Which operator is used for input in C++?

a)

>

b)

<

c)

=

d)

==

8.

Which of the following is a valid C++ variable name?

a)

2num

b)

num-1

c)

num_1

d)

num 1

9.

Which keyword is used to declare a class in C++?

a)

struct

b)

object

c)

class

d)

define

10.

Which of the following is NOT a C++ data type?

a)

int

b)

float

c)

string

d)

real

11.

What is the correct syntax to start the main function?

a)

void main()

b)

main()

c)

int main()

d)

start()

12.

Which operator is used for comparison?

a)

=

b)

==

c)

!=

d)

Both B and C

13.

Which loop executes at least once?

a)

for

b)

while

c)

do-while

d)

foreach

14.

Which of the following is used for comments in C++?

a)

/* */

b)

//

c)

#

d)

Both A and B

15.

Which concept allows function overloading in C++?

a)

Inheritance

b)

Polymorphism

c)

Encapsulation

d)

Abstraction

16.

Which keyword is used to define a structure in C++?

a)

structure

b)

struct

c)

class

d)

define

17.

Members of a structure are public by default.

a)

True

b)

False

18.

In a union, how many members can store values at a time?

a)

All members

b)

Only one member

c)

Two members

d)

Depends on compiler

19.

Which keyword is used to define a union?

a)

struct

b)

class

c)

union

d)

object

20.

Which of the following correctly declares an integer array of size 5?

a)

int arr;

b)

int arr(5);

c)

int arr[5];

d)

array int[5];

21.

Array indexing in C++ starts from:

a)

1

b)

0

c)

−1

d)

Depends on data type

22.

Which keyword is used to define a class in C++?

a)

struct

b)

object

c)

class

d)

define

23.

Members of a class are ______ by default.

a)

public

b)

protected

c)

private

d)

static

24.

How is an object created for a class Student?

a)

Student();

b)

class Student s;

c)

Student s;

d)

object Student s;

25.

Which operator is used to access data members of a class using an object?

a)

:

b)

::

c)

.

d)

->

26.

What is the output of the following code: int x = 10; cout << x;

a)

0

b)

10

c)

x

d)

Error

27.

Output of the following code: int x = 5; cout << x++;

a)

6

b)

5

c)

Error

d)

4

28.

Output of the following code: int a[3] = {10, 20, 30}; cout << a[2];

a)

10

b)

20

c)

30

d)

Error

29.

Output of the following code: for(int i = 0; i < 3; i++) cout << i;

a)

123

b)

012

c)

321

d)

013

30.

Output of the following code: int x = 0; if(x) cout << "Yes"; else cout << "No";

a)

Yes

b)

No

c)

0

d)

Error

31.

Output of the following code: struct Test { int a; }; int main() { Test t; t.a = 7; cout << t.a; }

a)

0

b)

7

c)

Garbage value

d)

Error

32.

Output of the following code: class Demo { public: int x = 5; }; int main() { Demo d; cout << d.x; }

a)

0

b)

5

c)

Error

d)

Garbage value

33.

Output of the following code: int x = 3; cout << ++x;

a)

3

b)

4

c)

5

d)

Error

34.

Output of the following code: union Data { int a; char b; }; int main() { Data d; d.a = 66; cout << d.b; }

a)

66

b)

B

c)

A

d)

Error

35.

Output of the following code: int fun() { return 10; } int main() { cout << fun(); }

a)

fun

b)

0

c)

10

d)

Error