wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C C++ Final Test 20-APR-2022

Total questions: 78

Worksheet time: 54mins

Name
Class
Date
1.

Which of the following are themselves a collection of different data types?

a)

String

b)

Struct

c)

char

d)

all

2.

Which operator connects the structure name to its member name?

a)

-

b)

=

c)

.

d)

>>

3.

Which of the following cannot be a structure member?

a)

another structure

b)

array

c)

Function

d)

None

4.

What is the output of this C code?

void main()

{

struct student

{

int no;

char name[20];

};

struct student s;

s.no = 8;

printf("%d", s.no);

}

a)

Nothing

b)

Compile error

c)

8

d)

Junk

5.

Size of a union is determined by size of the.

a)

First member in the union

b)

Last member in the union

c)

C. Biggest member in the union

d)

Sum of the sizes of all members

6.

What will be the output

a)

Name:

Subject:

Percentage: 86.50000

b)

Name:Raju

Subject:

Percentage: 86.50000

c)

Name: Raju

Subject: Maths

Percentage: 86.50000

d)

Error

7.

Memory allocated for structure members are always contigious

a)

True

b)

False

8.

What do you understand by:

void update(struct student *s);

a)

update is a function that takes an argument as pointer to structure variable and returns nothing

b)

update is a method that takes structure type variable as parameter

c)

Error, we cannot pass structure variable as pointer to a function

d)

update takes pointer argument but it cannot return void

9.

Local variables are stored in an area called____________

a)

Heap

b)

Permanent storage area

c)

Stack

d)

Free memory

10.

The size of both stack and heap remains the same during run time.

a)

True

b)

False

11.

What is the return type of malloc() or calloc()?

a)

Pointer of allocated memory type

b)

void**

c)

void*

d)

int*

12.

The expression:


int *p = new int[20];

a)

allocates 20 integers and assigns the base address to p

b)

allocates 20 integers off the stack local to a block

c)

reads in 20 integer values from cin

d)

allocates an integer of size 20 bytes

13.

What does the variable i contain after the following code executes?


int i = 17;

int *p = &i;

*p = 98;

a)

98

b)

17

c)

81

d)

0

14.

Every byte in the computer's memory is assigned a unique:

a)

pointer

b)

address

c)

dynamic allocation

d)

name

15.

If a variable uses more than one byte of memory, for pointer purposes its address is:

a)

the address of the last byte of storage

b)

the average of all the addresses used to store that variable

c)

the address of the first byte of storage

d)

the address of the second byte of storage

16.

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

a)

asterisk (* )

b)

ampersand ( & )

c)

percent sign ( % )

d)

exclamation point ( ! )

17.

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

18.

A pointer variable is designed to store

a)

any legal C++ value

b)

only floating-point values

c)

an integer

d)

a memory address

19.

Dynamic memory allocation occurs

a)

when a new variable is created by the compiler

b)

when a new variable is created at runtime

c)

when a pointer fails to dereference the right variable

d)

when a pointer is assigned an incorrect address

20.

What is the output of following program?

a)

20

b)

30

c)

Compile Error

d)

Runtime Error

21.

Arrays always occupy contiguous memory area

a)

True

b)

False

22.

Which of the following format specifier in printf is used to print pointers?

a)

%c

b)

%d

c)

%f

d)

%p

23.

A pointer is

a)

A keyword used to create variables

b)

A variable that stores address of an instruction

c)

A variable that stores address of a varaibe

d)

All of the above

24.

What is the & in pointers?

a)

Dereferences the memory address into an object

b)

References an object into a memory address

c)

Makes a new copy of the object as a memory address

d)

None of the above.

25.

How do you make a pointer point to an existing variable?

int y = 0;

a)

int *x = y;

b)

int x = y;

c)

int *x = &y;

d)

int &x = *y;

26.

The process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself is known as:

a)

repetition

b)

recursion

c)

reapparition

d)

reversing

27.

Which of the following is the best definition of a recursive method?

a)

A method that iterates itself exactly 5 times.

b)

A method that invokes itself by name within the method.

c)

A method that will never iterate infinitely.

d)

A method that cannot be called more than once.

28.

Recursion is similar to which of the following?

a)

if-else

b)

switch-case

c)

loops

d)

none of the above

29.

The following function finds the factorial of any number


int factorial(int n)

{

if(n == 0 || n == 1) return 1;


return n * factorial(n-1);

}


What would calling factorial(4) output?

a)

24

b)

16

c)

8

d)

64

30.

The following function finds the factorial of any number


int factorial(int n)

{

if(n == 0 || n == 1) return 1;


return n * factorial(n-1);

}


What would calling factorial(2) output?

a)

12

b)

2

c)

0

d)

22

31.

Make the following function return the following number in the fibonacci sequence


int fibo(int n)

{

if(n == 0 || n == 1) return n;

return _________________;

}

a)

fib (n-1)+fib (n-2)

b)

fibo(n-1)+fibo(n-2)

c)

fibo(n*2)

d)

fibo(n+1)+fibo(n+2)

32.

2. Which statement best describes logic errors?

a)

An error in a program that causes it to produce incorrect ouputs but not a crash.

b)

An error in a program that causes it to crash.

c)

An error in the program caused by mis-spelt instructions.

d)

An error in a program caused by hardware failure.

33.

6.Find error/ output in following code

How many times " placement Questions" will print.

int main

{

int x;

for ( x=1;x <=10; x++)

{

if ( x < 5)

Continue;

else

break;

Printf (" placement Question ");

{

return 0;

}

a)

Infinite time

b)

11 times

c)

0 time

d)

10 times

34.

11.Is there any limit in adding no of header files in program?

a)

yes

b)

no

35.

14.what will be the output?

#include <stdio.h>


void decrement();


int main()

{

decrement();

decrement();

decrement();

return 0;

}


void decrement()

{

int i = 5;

printf("%d",i);

i--;

}

a)

A) 555

b)

(B) 543

c)

(C) 545

d)

(D) 544

36.

The Parameter list in main function represent ------- parameter

a)

formal parameter

b)

argument list

c)

actual parameter

d)

above all

37.

A function declaration is also known as function ----------

a)

prototype

b)

call

c)

definition

d)

above all

38.

int x;

int y;

int z;

x=3;

y=4;

z = ++x * y++;

printf("%d",z);

a)

12

b)

16

c)

20

d)

0

39.

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

40.

Which operator has the lowest priority?

a)

++

b)

%

c)

+

d)

||

41.

int main()

{

int a = 25%10;

printf("%d", a);


return 0;

}

a)

5

b)

2

c)

2.5

d)

5.5

42.

The modulus operator (%) can be used only with integers.

a)

True

b)

False

43.

!= is the example of ____________________ operator.

a)

Relational

b)

Logical

c)

Assignment

d)

Conditional

44.

The _____________ operator checks if the value of left operand is greater than the value of right operand.

a)

= =

b)

<

c)

>

d)

=

45.

#include <stdio.h>


int main()

{


int i = 95;


char c = 97;


printf("%d, %d\n", sizeof(i), sizeof(c));


return 0;

}

a)

2,1

b)

4,2

c)

2,4

d)

2,8

46.

#include <stdio.h>


void main()

{


int x = 5 * 9 / 3 + 9;


}

a)

24

b)

3

c)

23

d)

4

47.

What is the output of C Program.?

int main()

{

int a[] = {1,2,3,4};

int b[4] = {5,6,7,8};

printf("%d,%d", a[0], b[0]);

}

a)

1

b)

2

c)

4

d)

Error

48.

What is the output of C Program.?

int main() {

int a[] = {1,2,3,4};

int b[4] = {5,6,7,8};

printf("%d,%d", a[0], b[0]);

}

a)

1,5

b)

2,6

c)

0,0

d)

Error

49.

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

50.

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

51.
The process of creating a new variable without value
a)
declaration
b)
naming
c)
instantiation
d)
assigning
52.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

53.
Which command moves the shown text to the next line?
a)
\t
b)
\n
c)
\r
d)
\s
54.
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
55.
What is the output of this program?
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
a)
"Hi everybody"
b)
Hi everybody"
c)
Hi everybody
d)
"Hi everybody
56.

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

a)

>

b)

<=

c)

=

d)

==

57.

Evaluate the following expressions to true or false


3!=4-1

a)

true

b)

False

58.

Evaluate the following expressions to true or false


5 >= (1+6)-4

a)

True

b)

False

59.

Evaluate the following expressions to true or false

5+1==6 || 8-1>4

a)

True

b)

False

60.

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

61.

Each pass through a loop is called a/an

a)

pass through

b)

enumeration

c)

iteration

d)

culmination

62.

In a group of nested loops, which loop is executed the most number of times?

a)

the outermost loop

b)

the innermost loop

c)

all loops are executed the same number of times

d)

cannot be determined without knowing the size of the loops

63.

The statement i++; is equivalent to

a)

i = i + i;

b)

i = i + 1;

c)

i = i - 1;

d)

i --;

64.

What's wrong? for (int k = 2, k <=12, k++)

a)

the increment should always be ++k

b)

the variable must always be the letter i when using a for loop

c)

there should be a semicolon at the end of the statement

d)

the commas should be semicolons

65.

C Language is a successor to which language.?

a)

FORTRAN

b)

D Language

c)

BASIC

d)

B Language

66.

C language was invented in which laboratories.?

a)

Uniliver Labs

b)

IBM Labs

c)

AT&T Bell Labs

d)

Verizon Labs

67.

A C program is a combination of.?

a)

Statements

b)

Function

c)

variables

d)

all

68.

An Identifier may contain.?

a)

Letters a-z, A-Z in Basic character set.

Unicode alphabet characters other languages

b)

Underscore _ symbol

c)

Numbers 0 to 9

Unicode Numbers in other languages

d)

All the above

69.

Choose correct statements

a)

A constant value does not change.

A variable value can change according to needs.

b)

A constant can change its values.

A variable can have one constant value only.

c)

There is no restriction on number of values for constants or variables.

d)

Constants and Variables can not be used in a singe main function.

70.

Find an integer constant.

a)

3.145

b)

34

c)

"125"

d)

None of the above

71.
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
72.

After running the following code, what will be the value of apples?

apples = 3;

apples++;

a)

4

b)

5

c)

3

d)

0

73.

What will this code output?

int banana = 3;

banana += 5;

cout<<banana;

a)

3

b)

5

c)

8

d)

15

74.

Which of these variables can contain decimal numbers?

a)

int apples;

b)

double apples;

c)

char apples;

d)

void apples;

75.

What is the alternative for x = x + 5?

a)

x += 5;

b)

x -= 4;

c)

x = y + 5;

d)

x=+5

76.

What is the alternative for y = y * 2?

a)

y = * 2;

b)

y*= 2

c)

y **;

d)

x=+2;

77.

How can we store a user input to the variable

int apples; ?

a)

cin << int apples;

b)

cin >> apples;

c)

cin;

78.

What will this code output?

int apples = 3;

int bananas = apples * 2;

cout<<banana << "," <<apples;

a)

3, 6

b)

3, 3

c)

6, 3

d)

6, 6