wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Fundamentals

Total questions: 30

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is a valid C++ identifier?

a)

2value

b)

value_2

c)

int

d)

for

2.

Which header file is required for cout and cin?

a)

A) stdio.h

b)

B) iostream

c)

C) conio.h

d)

D) stdlib.h

3.

What is the default value of an uninitialized local variable in C++?

a)

0

b)

Garbage value

c)

NULL

d)

-1

4.

Which data type is best for storing a single character?

a)

string

b)

char

c)

char[]

d)

bool

5.

What will sizeof(int) typically return?

a)

1

b)

2

c)

4

d)

Depends on compiler

6.

Which type conversion is done automatically?

a)

Explicit

b)

Implicit

c)

Manual

d)

Casting only

7.

What is the result of 10 / 3 in integer division?

a)

A) 3.33

b)

B) 3

c)

C) 4

d)

D) Error

8.

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

a)

A) 11

b)

B) 21

c)

C) 7

d)

D) 17

9.

Which operator has highest precedence?

a)

+

b)

=

c)

*

d)

++ (postfix)

10.

What does == do?

a)

Assigns value

b)

Compares values

c)

Checks address

d)

None

11.

What is the output of: int a = 1; cout << a++ << endl;

a)

A) 1

b)

B) 2

c)

C) 0

d)

D) Error

12.

Which statement is TRUE about if?

a)

It must have an else

b)

Condition must be in parentheses

c)

It ends with semicolon

d)

It cannot be nested

13.

What will this print? int x = 5; if (x = 3) cout << "Yes"; else cout << "No";

a)

Yes

b)

No

c)

Error

d)

Nothing

14.

The switch statement works with:

a)

float

b)

string (C++11+)

c)

char

d)

Both B and C

15.

Which is equivalent to if (a > b)?

a)

a < b

b)

a == b

c)

!(a <= b)

d)

!(a >= b)

16.

How many times will this loop run? for(int i=0; i<5; i++);

a)

5

b)

4

c)

0

d)

1

17.

while loop checks condition:

a)

Before execution

b)

After execution

c)

Randomly

d)

Only once

18.

Which loop runs at least once?

a)

for

b)

while

c)

do-while

d)

None

19.

What does break do?

a)

Skips current iteration

b)

Stops entire loop

c)

Ends program

d)

Goes to next iteration

20.

What is wrong here? for(int i=0; i<10; i--)

a)

Syntax error

b)

Infinite loop

c)

Runs 10 times

d)

Skips all

21.

What is the correct syntax of a function definition?

a)

A) returnType functionName(parameters) {}

b)

B) functionName returnType(parameters) {}

c)

C) returnType(parameters) functionName {}

d)

D) functionName(parameters) returnType {}

22.

What is a parameter?

a)

Value inside function call

b)

Value inside function definition

c)

Return type

d)

Local variable

23.

What is function overloading?

a)

Using too many functions

b)

Same name, different parameters

c)

Same parameters, different names

d)

Functions inside functions

24.

What will this return? int fun() { int x = 10; return x; }

a)

Nothing

b)

0

c)

10

d)

Error

25.

Arrays in C++ are:

a)

Fixed size

b)

Dynamic

c)

Changeable at runtime

d)

Unlimited

26.

What is the index of the first element?

a)

-1

b)

0

c)

1

d)

Depends

27.

Which correctly declares a string?

a)

char name[10];

b)

string name;

c)

Both A and B

d)

int name;

28.

What does int *p; mean?

a)

p stores an integer

b)

p is a pointer to an integer

c)

p is an array

d)

p is a function

29.

If int a = 5; int *p = &a; what is *p?

a)

Address of a

b)

Value 5

c)

Pointer itself

d)

Error

30.

What is the output? int a = 5, b = 10; if (a < b && b > 5) cout << "True"; else cout << "False";

a)

True

b)

False

c)

Error

d)

No output