wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C/C++ programming basics

Total questions: 50

Worksheet time: 36mins

Name
Class
Date
1.

The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed

a)

at least once

b)

at least twice

c)

never

d)

as many times as the user wishes

2.

What will be the output of the following code?

int i=1;

for ( ; ; )

cout << ++i;

a)

1 2 3 4 5. . . (infinite)

b)

2 3 4 5 6. . . . (infinite)

c)

error

d)

can't say

3.

If you want a user to enter exactly 20 values, which loop would be the best to use?

a)

while

b)

switch

c)

do-while

d)

for

4.

How many times will the above loop display "Hello world!"?

a)

19

b)

20

c)

21

d)

an infinite number of times

5.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2 4

d)

0 1 2

6.

Loops in C Language are implemented using?

a)

While Block

b)

For Block

c)

Do While Block

d)

All the above

7.

If block always need to be associated with a else block?

a)

True

b)

False

8.

Choose a right C Statement.

a)

Loops or Repetition block executes a group of statements repeatedly

b)

Loop is usually executed as long as a condition is met

c)

Loops usually take advantage of Loop Counter

d)

All the above

9.

The conditional operator are also known as

a)

Relational operator

b)

Binary operator

c)

Ternary operator

d)

Chary operator

10.

If you have to make decision based on multiple choices, which of the following is best suited?

a)

if

b)

if-else

c)

if-else-if

d)

All the above

11.

Can we use string inside switch statement?

a)

Yes

b)

No

12.

In situations where we need to execute body of the loop before testing the condition, we should use __________.

a)

for

b)

while

c)

do while

d)

nested for loop

13.

What is the output of the above program?

a)

0 1 2 3 4

b)

0 1 2 3

c)

0 1 2

d)

0 1

14.

Choose a correct C Statement.

a)

a++ is (a=a+1) POST INCREMENT Operator

b)

a-- is (a=a-1) POST DECREMENT Opeartor

--a is (a=a-1) PRE DECREMENT Opeator

c)

++a is (a=a+1) PRE INCREMENT Operator

d)

All the above.

15.

What is the way to suddenly come out of or Quit any Loop in C Language.?

a)

continue; statement

b)

leave; statement

c)

break; statement

d)

quit; statement

16.

What will be the output of the following program?

a)

a) 0 1 2 3 4

b)

b) 5

c)

c) Error

d)

d) No output

17.

How many arrows should come out of a decision symbol in a flowchart?

a)

0

b)

1

c)

2

d)

3

18.

What does selection mean?

a)

Selection is following instructions in order.

b)

Selection is to repeat something over and over again

c)

Selection is when you have a choice of options

d)

Selection is choosing the best option

19.

int x;

int y;

int z;

x=3;

y=4;

z = ++x * y++;

cout<<z;

a)

12

b)

16

c)

20

d)

0

20.

Which of the following comments about the ++ operator are correct?

1) It is a unary operator

2) The operand can come before or after the operator

3)It associates from the right

a)

1 and 3

b)

1 and 2

c)

2 and 3

d)

1,2,3

21.

Which of the following is not a Bitwise operator?

a)

&

b)

|

c)

<<

d)

&&

22.

16>>2

a)

4

b)

8

c)

32

d)

64

23.

What is the output of the following code:

#include<stdio.h>

void main()

{

int a=10,b=-5;

printf("%d",a&&b);

}

a)

1

b)

0

c)

Error

d)

10

e)

-5

24.

What will be the output of the following program?

a)

a) 10 11 12 13 ...

b)

b) 10

c)

c) No output

d)

d) Infinite loop

25.

What is the output of the following code snippet:


int a=12;

a?printf("GEC"):printf("IT");

a)

GEC

b)

IT

c)

GECIT

d)

Error

26.

What will be the output of the following program?

a)

a) 0 1 2 3 4

b)

b) Infinite loop

c)

c) 0 0 0 0 0

d)

d) No output

27.

Which of the following is a valid way to declare a variable in C?

a)

int 1a;

b)

int a1;

c)

float a-b;

d)

char a@;

28.

What will be the output of the following code:

int x = 5; printf("%d", x++);

a)

5

b)

Error

c)

6

d)

None

29.

Which of the following statements is true about the 'break' statement?

a)

It can only be used in loops.

b)

Both a and b

c)

It can be used to exit a function.

d)

It can be used to exit a switch statement.

30.

Which of the following is true about the 'continue' statement?

a)

It terminates the program.

b)

It can only be used in switch statements.

c)

It skips the current iteration of a loop.

d)

It can be used in any block of code.

31.

What is the output of the following code snippet: for(int i=0; i<5; i++) { printf("%d ", i); }?

a)

0 1 2 3 4 5

b)

No output

c)

0 1 2 3 4

d)

1 2 3 4 5

32.

Which of the following statements about nested loops is correct?

a)

They are not allowed in C programming.

b)

They can only be used with for loops.

c)

They can improve performance in all cases.

d)

They allow a loop to be executed within another loop.

33.

What is the output of C Program.?

int main() {

int a[3] = {10,12,14};

a[1]=20;

int i=0;

while(i<3)

{ printf("%d ", a[i]);

i++; }

}

a)

20 12 14

b)

10 20 14

c)

10 12 20

d)

Error

34.

What is the output of C program.?

int main() {

int a[3] = {10,12,14};

int i=0;

while(i<3)

{ printf("%d ", i[a]);

i++; }

}

a)

14 12 10

b)

10 10 10

c)

10 12 14

d)

None

35.

8.Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?

a)

arr[6]

b)

arr[7]

c)

arr{6}

d)

arr{7}

36.

What is the minimum and maximum Indexes of this below array.?

int main()

{

int ary[9];

return 0;

}

a)

-1, 8

b)

0, 8

c)

1,9

d)

None of the above

37.

Which of the following gives the memory address of the first element in array foo, an array with 100 elements?

a)

foo[0];

b)

foo;

c)

&foo;

d)

foo[1];

38.

Choose a correct array statement.

a)

An array size can not changed once it is created.

b)

Array element value can be changed any number of times

c)

To access Nth element of an array students, use students[n-1] as the starting index is 0.

d)

All the above

39.

Explain the concept of pointer arithmetic with an example in C++.

a)

Pointer arithmetic involves multiplying a pointer by an integer value to access elements of an array.

b)

Pointer arithmetic in C++ is used to perform mathematical operations on the memory address of a pointer.

c)

In C++, pointer arithmetic can only be performed on pointers to primitive data types.

d)

Pointer arithmetic in C++ involves adding or subtracting an integer value to/from a pointer to access elements of an array. For example, if 'ptr' is a pointer to an integer, then 'ptr + 1' will point to the next integer in memory.

40.

What happens when you subtract one pointer from another in C++?

a)

It gives the sum of the two pointers

b)

It gives the number of elements between the two pointers, divided by the size of the type to which the pointers point.

c)

It gives the difference of the two pointers

d)

It gives the product of the two pointers

41.

The __________, also known as the address operator, returns the memory address of a variable.

a)

asterisk (* )

b)

ampersand ( & )

c)

percent sign ( % )

d)

exclamation point ( ! )

42.

What does the following statement do?

double *num2;

a)

Declares a double variable named num2

b)

Declares and initializes a pointer variable named num2

c)

Initializes a pointer variable named num2

d)

Declares a pointer variable named num2

43.

Assuming ptr is a pointer variable, what will the following statement output?

cout << *ptr;

a)

the value stored in the variable whose address is contained in ptr

b)

the string "*ptr"

c)

the address of the variable whose address is stored in ptr

d)

the address of the variable stored in ptr

44.

A pointer variable is designed to store

a)

any legal C++ value

b)

only floating-point values

c)

an integer

d)

a memory address

45.

How do you assign the address of variable score to pointer pScore in C++?

a)

pScore = *score;

b)

pScore = &score;

c)

pScore = score;

d)

pScore = score&;

46.

What does the expression *pScore = newScore; do?

a)

It reassigns pScore to point to newScore.

b)

It changes the value of pScore to the address of newScore.

c)

It changes the value of the object that pScore points to, to the value of newScore.

d)

It creates a new pointer called newScore.

47.

How are the elements of an array stored in memory?

a)

In a non-contiguous block of memory

b)

In a contiguous block of memory

c)

In a random order in memory

d)

In separate memory locations for each element

48.

What do the following declaration signify? char *arr[10];

a)

arr is a array of 10 character pointers.

b)

arr is a array of function pointer

c)

. arr is a array of characters

d)

. arr is a pointer to array of characters

49.

What is the output of the following program int main()

{  

 int a = 20;  

 //a memory location = 1234   

printf("%d %d %d %d", a, &a, *(&a));  

 return 0; }

a)

20 20 20

b)

20 1234 1234

c)

20 1234 20

d)

1234 20 1234

50.

  "&" is called as ___________ in pointer concept.

a)

Conditional Operator

b)

Address Operator

c)

Logical Operator

d)

None of these