0% found this document useful (0 votes)
309 views

Exit Exam CPP - 2

This document contains a sample exam for a C++ exit exam with 36 multiple choice questions covering various fundamental C++ concepts. The questions test knowledge in areas like problem solving life cycle steps, algorithm properties, array declaration, OOP concepts like inheritance and encapsulation, access specifiers, loop syntax, control structures, variables names and data types.

Uploaded by

Eden Admasu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views

Exit Exam CPP - 2

This document contains a sample exam for a C++ exit exam with 36 multiple choice questions covering various fundamental C++ concepts. The questions test knowledge in areas like problem solving life cycle steps, algorithm properties, array declaration, OOP concepts like inheritance and encapsulation, access specifiers, loop syntax, control structures, variables names and data types.

Uploaded by

Eden Admasu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Fundamental of Programming or Introduction to Computing

C++ EXIT EXAM SAMPLE QUESTIONS

1. In which steps of problem solving life cycle what input data are needed to solve problem,
what procedure is needed to achieve the result and what output are expected are identified
A. Analysis (problem specification)
B. Algorithm design.
C. Implementation or coding
D. Maintenance and documentation
2. Finiteness property of an Algorithm is
A. The number of steps in the algorithm should be finite.
B. The algorithm should terminate after a finite no. of times.
C. For all possible combinations of input data, the algorithm terminates after a finite
no. of steps
D. A and C
3. Which of the following approach is used by C++?
A. Left-right C. Right-left
B. Bottom-up D. Top-down
4. Which of the following correctly declares an array in C++?
A. array{10}; C. array array[10];
B. int array; D. int array[10];
5. Which concept allows you to reuse the written code in C++?
A. Inheritance C. Abstraction
B. Polymorphism D. Encapsulation
6. To which of the following access specifiers are applicable?
A. Member data C. Both Member data & Functions
B. Functions D. Protected members
7. Which of the following refers to characteristics of an array?

A. An array is a set of similar data items


B. An array is a set of distinct data items
C. An array can hold different types of datatypes
D. None of the above
8. Which of the following can be considered as the object of an array?

A. Index of an array
B. Elements of the Array
C. Functions of the Array
D. All of the above

9. Which of the following statements is correct about the class?

A. An object is an instance of its class


B. A class is an instance of its object
C. An object is the instance of the data type of that class
D. Both A and C

10. Which of the following statements supports that reusable code should be one of the
desirable features of any language?

A. It helps in reducing the maintenance cost


B. It helps in reducing the testing time
C. It helps in reducing both the maintenance time and testing time
D. It helps in reducing the compile time

11. Which of the following concept refers to adding new components to the program at the
run time?

A. Dynamic Loading
B. Dynamic binding
C. Data hiding
D. Both A & B

12. How are the references different from the pointer?

A. A reference cannot be modified once it initialized


B. There is no need of an extra operator for dereferencing of a reference
C. A reference cannot be NULL
D. All of the above

13. Which one of the following correctly refers to the command line arguments?

A. Arguments passed to the main() function


B. Arguments passed to the structure-function
C. Arguments passed to the class functions
D. Arguments passed to any functions
14. What will happen when we move the try block far away from catch block?

A. Reduces the amount of code in the cache


B. Increases the amount of code in the cache
C. Don't alter anything
D. Increases the amount of code

15. Which one of the following given statements is correct about the increment operator?

A. Increment operator(or ++ ) usually adds 2 to its operand


B. Decrement operator ++ subtracts 1 to its operand
C. Decrement operator ++ subtracts 3 to its operand
D. Increment operator (or ++ ) usually adds 1 to its operand

16. Which one of the following statements about the pre-increment is true?

A. Pre Increment is usually faster than the post-increment


B. Post-increment is faster than the pre-Increment
C. Pre increment is slower than post-increment
D. pre decrement is slower than post-increment

17. Why inline functions are useful?

A. Functions are large and contain several nested loops


B. Usually, it is small, and we want to avoid the function calls
C. The function has several static variables
D. All of the above

18. In C++, which of the following has the associatively of left to right?

A. Addressof
B. Unary operator
C. Logical not
D. Array element access

19. Which of the following can be considered as the correct syntax of for loop?

A. for(initialization; condition; increment/decrement operator){}


B. for(initialization, condition; increment/decrement operator){}
C. for(initialization; increment/decrement operator;condition;{}
D. None of the above
20. The term modularity refers to _____.

A. To divide the program into small independent parts or sub-modules


B. To override the parts of the program
C. To wrapping things into a single unit
D. None of the above

21. Which of the following methods can be considered the correct and efficient way of
handling arguments with spaces?

A. Use single quotes


B. Either single or double quotes
C. Use double quotes
D. There is no way of handling arguments with space

22. What is the value of p in the following C++ code snippet?


#include <iostream>
using namespace std;
int main(){
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x | y) + (a + b));
cout << p;
return 0;
}
A. 12 B. 14 C. 2 D. 16

23. Which of the following statement is incorrect about preprocessor directives?

A. These are lines read and processed by the preprocessor


B. They do not produce any code by themselves
C. These must be written on their own line
D. They end with a semicolon

24. Which of the following is correct about this pointer in C++?


A. this pointer is passed as a hidden argument in all static variables of a class
B. this pointer is passed as a hidden argument in all the functions of a class
C. this pointer is passed as a hidden argument in all non-static functions of a class
D. this pointer is passed as a hidden argument in all static functions of a class
25. What is the difference between a declaration and a definition of a variable?
A. Both can occur multiple times, but a declaration must occur first.
B. A definition occurs once, but a declaration may occur many times.
C. A declaration occurs once, but a definition may occur many times.
D. Both can occur multiple times, but a definition must occur first.
26. Which development phase of problem solving life cycle Method is used to verify
correctness and that requirements are met or not.
A. Testing B. Debugging C. Analysis D. Maintenance
27. A statement that is executed in a repetition structure, skips the remaining statement in the
body of structure and proceeds with next iteration of loops, is known as
A. Break statement
B. Continue statement
C. Case statement
D. None of them
28. Identify the correct order for the program execution
A. Object code, Source code, Executable code.
B. Source code, Object code, Executable code.
C. Running, Debugging, Compiling,
D. Running, Compiling, Debugging.
29. Which of the following loop is normally used for a menu driven program?
A. Do While Loop C. While Loop
B. For Loop D. Do Loop
30. Which of the following is the correct order of program execution in “for loop” based on
the syntax below.
For (initialization; condition; increment/Decrement) {
//body of the loop
}
i. Condition is checked iii. Increment/Decrement
ii. Initialization is executed iv. statement is executed
A. ii, i, iv and iii C. ii, iv,iii and i
B. ii,i,iv and iii D. ii,iv,iii and i
31. Which of the following is not a legal variable name?

A. _something
B. aVariable
C. float2string
D. 2manyLetters
E. X

32. Which numeric data type has the largest range?


a. int
b. char
c. float
d. double
33. In C++, out of range array index is what type of error

a. Compile time
b. Run time
c. Is not an error
d. None

34. How many times is the phrase ″In the loop″ printed when the following code is executed?

int i, j=25;
for(i=0; i<j; i++, j--)
{
if(i%2==0)
continue;
cout << ″In the loop″ << endl;
}
a. 6 b. 10 c. 4 d. 5 e. 2
35. What are the three basic control structures used in programming?
a. int, double, string
b. while, do..while, for
c. sequence, decision, repetition
d. input, output, and calculation
36. A loop exit condition must
a. be the last instruction in the body of the loop
b. evaluate to true or false
c. be the first instruction in the body of the loop
d. not use compound conditions
37. A variable which is declared inside the function can be called?

a. Local variable
b. Global variable
c. Normal variable
d. Variable scope

38. If the logic of your program at some point requires you to do one thing or another, which
instruction would you use to implement this decision?
a. while
b. for
c. if..else
d. sequence
e. cin
39. Consider the following code fragment carefully, then answer the question: how many
times will the cout statement execute:

for (i = 0; i < 5; i++);


cout << i;

a. 5 times
b. 4 times
c. 6 times
d. 0 times
e. 1 time
40. Find the output of the following code:
int main() {
int x = 10;
cout << -- x + 1<<",";
cout<< x++; }
a. 10, 9
b. 10, 10
c. 9, 10
d. 9, 9
e.
41. Tasks performed by the OS include:
a. Management of secondary storage devices.
b. Memory management
c. Allocation of CPU time
d. All
42. which is not a part of every C++ function.
a. Function header
b. Function body
c. Function selector
d. Function parameters
e. All expect c
43. which one is different from others?
a. int a ;
b. float b;
c. double d;
d. int c = 40;
44. How many times will the print statement be executed?

main(){
int i = 0;
label:
cout << “Interviewbit;
i++;
if(i < 3){
goto label;
}
}
a. times
b. times
c. times
d. error
45. What is the output of the following c++ source code.

float mark = 50.0L;

if(mark > 85)


cout <<"Your grade is A ";
cout << "Excellent!";

a. Your grade is A Excellent!


b. Nothing will be Displayed.
c. Excellent!
d. Your grade is A

46. Given the following Statements:


int grade[3] = {65, 50, 86};
what is the output of ?

cout << *grade;

a. 65
b. 50
c. 65, 50, 86
d. It is an invalid statement.
47. How many times is the phrase ″In the loop″ printed when the following code is executed?

int a = 4, b = 12;
do{
cout << ″in the loop″<< endl;
a+=2;
b-=2;
} while(a<b);
A. 1 B. 2 C. 3 D. 4 E. 5

48. Given the following function:


void calculateArea (float& a , float r)
{
a = r * r * 3.14;
}
Assume that float area = 0; float radius = 5; is declared in main (). what is the correct way
to call (invoke) the above function.
a) calculateArea(area, radius);
b) area = calculateArea(radius);
c) calculateArea(&area, radius);
d) calculateArea(area);

49. Which of the following approach is used by C++?


a. Left-right
b. Right-left
c. Bottom-up
d. Top-down
50. What happens if the following C++ statement is compiled and executed?

int *ptr = NULL;


delete ptr;

a) The program is not semantically correct


b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time

51. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}

a) Hello
b) World
c) Error
d) Hello World

52. Which of the following is correct about this pointer in C++?


a) this pointer is passed as a hidden argument in all static variables of a class
b) this pointer is passed as a hidden argument in all the functions of a class
c) this pointer is passed as a hidden argument in all non-static functions of a class
d) this pointer is passed as a hidden argument in all static functions of a class
53. What will be the output of the following C++ function?

int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}

a) Runtime error may be possible


b) Compiler error may be possible
c) 1
d) 0

54. Which of the following correctly declares an array in C++?


a) array{10};
b) array array[10];
c) int array;
d) int array[10];
55. Which is more effective while calling the C++ functions?
a) call by object
b) call by pointer
c) call by value
d) call by reference
56. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main()
{
char c = 74;
cout << c;
return 0;
}

a) I
b) J
c) A
d) N
57. What is the output of the following statements?

int k = 2, g = 20;
k *= g++;
cout << k << “ , ” << g;

a) 42 , 21
b) 40 , 21
c) 40 , 20
d) 2 , 40
58. What is the following statement?

int addition( int, int );


a) It is a Function invocation.
b) It is a Function prototyping.
c) It is not a valid C++ statement.
d) It is a variable declaration.
59. The C++ code which causes abnormal termination/behaviour of a program should be
written under _________ block.
a) catch
b) throw
c) try
d) finally
60. What is abstract class in C++?
a) Any Class in C++ is an abstract class
b) Class from which any class is derived
c) Class specifically used as a base class with atleast one virtual functions
d) Class specifically used as a base class with atleast one pure virtual functions
61. Which concept allows you to reuse the written code in C++?
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
62. How structures and classes in C++ differ?
a) Structures by default hide every member whereas classes do not
b) In Structures, members are public by default whereas, in Classes, they are private by
default
c) Structures cannot have private members whereas classes can have
d) In Structures, members are private by default whereas, in Classes, they are public by
default
63. What is the value of var?
int var;
var = 3 + 2 * 3 / 2 – (4 - 2);

a) 3 b) 5.5 c) 4 d) 5 e) not a valid c++ statement.

64. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}

a) 12
b) 14
c) 6
d) 7

65.
66. Which of the following is not correct about structures?
A. It is a programmer defined data types.
B. Structures can contain variables of different data types.
C. Members of structure are accessed through structure variable.
D. The default way of passing structure variable is by reference.
67. Which of the following pairs are incorrectly paired?
a. (cin, read from key board)
b. (cout, write to screen)
c. (ofstream, read from a file)
d. (fstream, write to a file)
68. A constructor is executed when a class is declared.
a. True
b. False
69. Which of the following access modifier is used in a constructor definition by default?
a. Protected
b. Public
c. Private
d. Either A or C
70. Which one of the following statements is true?
a. An ifstream object can create a file.
b. An ofstream object cannot create a file.
c. An ofstream object is used to write a file.
d. A and B

71. which one is not true about array?


a. heterogeneous datatype
b. homogeneous datatype
c. store continuous data’s
d. access the element of the array thought index
72. what is the definition of pointer?
a. variable that used to store the series of data
b. pointer is a variable that used to store the exact values of the variable
c. pointer is used to store the address ana another variable
d. pointer is a variable used to store the size of variable
73. what is pass by value?
a. pass the exact value of the variable to the certain function
b. pass the address of the variable to the certain function
c. pass the exact size of the variable to a certain function
d. all the above
74. Which of the following statement is false?
a. Function has two parts header and the body
b. It is possible to pass a paraments to a certain function
c. Void type has a return value of 1
d. Void type has return value of empty
75. Which of the following can be considered as the correct syntax for declaring an array of
pointers of integers that has a size of 10 in C++?
A. int *arr = new int*[10]
B. int *arr = new int[10];
C. int arr = new int[10];
D. int **arr = new int*[10];
76. When an ADT is implemented as a C++ class, which of the following should normally be
true?
A. Member functions are private, member variables are public
B. Member functions are public, member variables are private
C. Member functions as well as member variables are private
D. Member functions as well as member variables are public
77. What will happen while using pass by reference
A. The values of those variables are passed to the function so that it can manipulate
them
B. The location of variable in memory is passed to the function so that it can use the
same memory area for its processing
C. The function declaration should contain ampersand (& in its type declaration)
D. All of the mentioned

78. What is wrong with the following code fragment?


int main()
{
int x=4,y=3; // line 1
const int i = 10; // line2
x = x + i; // line 3
i = y*2; // line 4
}
A. Variables are not declared before use
B. There cannot be 3 variables in such a simple program
C. There is an error in line 3
D. There is an error in line 4
E. Both C and D
79. For the following code fragment, how many times does sum get incremented? In other
words, how many times is line X executed in the following program?
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
sum++;
}
}
A. 4
B. 3
C. 9
D. 2
E. None of the above

80. What is the value stored in c?


int a=4, b=9, c;
c = a++ + ++b;
A. 13 C. 14
B. 15 D. 12
81. The process of going from a set of source files to a running program has several steps.
Place the following in the correct order from the first step executed to the last:
I. Linking
II. Compiling
III. Execution
IV. Processing #include directives
A. II, IV, I, III
B. II, III, I, IV
C. IV, II, I, III
D. IV, I, II, III
E. I, IV, II, III
82. Given below are some statements about the default (0-argument) constructor:
I. Its return type is the type of the class
II. It has no return type
III. The programmer can define it, but the C++ language doesn’t require this
IV. The programmer must define it
V. It is always defined by C++ if it isn’t provided by the programmer
VI. It is sometimes, but not always, defined by C++ if it isn’t provided by the
programmer

Which of these statements are true?


A. I, III and V only
B. I, II and VI only
C. II and IV only
D. II, III and V only 3.
E. II, III and VI only
83. Which of the following functions will correctly return true if its argument is an odd
integer ?
I. bool IsOdd (int x) {
return (x % 2 == 1);
}
II. bool IsOdd (int x) {
return (x / 2 == 1);
}
III. bool IsOdd (int x) {
if (x % 2 == 1)
return true;
else
return false;
}
A. II only
B. I and II only
C. I and III only
D. II and III only 4.
E. I, II and III
84. Suppose you have a function prototype int foo(char *), and call it from main(), but forget
to write the code that actually implements foo - but everything else in your program is
correct. When will the error be detected, and what kind of error will it be?
A. The compiler will report an "undefined function body" error.
B. There will be an undefined error at run-time, because the compiler will generate code that
branches to an undefined address; anything could happen, so it is undefined.
C. Some very confusing compiler messages will result because the compiler will try to find
all possible overloads of functions that take a char * argument, of which there are many,
especially if the iostream header has been #included.
D. The linker will report an "undefined symbol" error for "foo" and no executable will be
built.
85. On most machines, addresses have the identical binary format, no matter what kind of
object they are the address of. Why then, is it necessary to declare a pointer variable with
the type of the pointed-to object?
A. It is a matter of readable programming style, but not required by the Standard.
B. If the pointer is used to access members of a class or a struct, the compiler must be able
to tell what class or struct is involved.
C. If the pointer is modified using pointer arithmetic, the size of the pointed-to object must
be known.
D. The premise of the question is false; pointers of different types usually have different
binary representations in the computer hardware
86. What is the output of the following code?
1. if ( 6 > 8)
2. {
3. cout << " ** " << endl ;
4. cout << "****" << endl;
5. }
6. else if (9 == 4)
7. cout << "***" << endl;
8. else
9. cout << "*" << endl;
A. ****
B. ***
C. *
D. **

87. Which of the following features of object oriented programming plays an important role
in allowing objects having different internal structures to share the same external
interfaces.

A. objects
B. classes
C. plymorphism
D. message passing

88. What is the effect of using small inline functions on the number of cache misses?

A. increase the number of cache misses


B. decrease the number of cache misses
C. No cache misses
D. None of these

89. If a derived class object is created, which constructor is called first?


A. Derived class constructor
B. Base class constructor
C. Totally Depends on that how we call the object
D. Both a and B

90. Observe following program and answer

class Example{

public: int a,b,c;

Example(){a=b=c=1;}

//Constructor 1

Example(int a){a = a; b = c = 1;}

//Constructor 2

Example(int a,int b){a = a; b = b; c = 1;}

//Constructor 3

Example(int a,int b,int c){ a = a; b = b; c = c;}

//Constructor 4

In the above example of constructor overloading, the following statement will call
which constructor

Example obj = new Example (1,2,3);

A. Constructor 2
B. Constructor 4
C. Constrcutor 1
D. Type mismatch error
91. What will be the output of the following C++ code?

#include <iostream>

#include <string>
using namespace std;

int main() {

string str {"Steve jobs"};

unsigned long int found = str.find_first_of("aeiou");

while (found != string :: npos)

str[found] = '*';

found = str.find_first_of("aeiou", found + 1);

cout << str << "\n";

return 0;
}
a. Steve
b. Jobs
c. St*v* j*bs
d. St*v*
i. Output of this program will be ____?
#include
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] – 8];
return 0;
}
A. 18
B. 15
C. garbage value
D. compile time error

92. What will be the output of this program?


#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {
result += array1[temp];
}
for (temp = 0; temp < 4; temp++) {
result += array2[temp];
}
cout << result;
return 0;
}
A. 6553
B. 6533
C. 6522
D. 12200

93. What happens when both of the following C++ programs are compiled and executed?

===== Program 1 =====


#include <iostream>
#include <array>

using namespace std;

int main()
{
array<int,5> arr1;
arr1.fill(5);
cout<<get<5>(arr1);
return 0;
}
=====================
===== Program 2 =====
#include <iostream>
#include <array>

using namespace std;

int main()
{
array<int,5> arr1;
arr1.fill(5);
cout<<arr1.at(5);
return 0;
}
=====================
a. Program 1 gives compile-time error and Program 2 gives run-time error
b. Program 1 gives run-time error and Program 2 gives compile-time error
c. Both programs results into compile-time error
d. Both programs results into run-time error

94. Identify the correct statements.

i. Derived class do not inherit or overload constructors or destructors from their base
classes.
ii. Destructors can be declared with the keyword virtual
iii. Constructors can be declared with the keyword virtual

A. (i) and (iii) only


B. (i) and (ii) only
C. (ii) and (iii) only
D. (i),(ii) and (iii)

95. Which option gives the correct interpretation of the following declaration in C++?

int (*x[10])();

a. X is a pointer to such function which return type is array


b. X is a pointer to an array of function
c. X is an array of ponters to functions
d. X is a pointer to functions.
96. Which of the following statement is true about preprocessor directives?
a. These are lines read and processed by the preprocessor
b. They do not produce any code by themselves
c. These must be written on their own line
d. They end with a semicolon
97. What is the output of the following program.

main(){

int i={1,2,3};

cout<<i<<endl;

a. 1
b. 123
c. 3
d. Error
98. What does the following code fragment print?

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

int[] b = { 1, 2, 3 };

System.out.println(a == b);

A. It prints true
B. It prints false.
C. Compile time error
D. None

99. Which from the following is not a correct way to pass a pointer to a function?

A. Non-constant pointer to non-constant data


B. A non-constant pointer to constant data
C. A constant pointer to non-constant data
D. All of the above

100. Which of the following is a correct identifier in C++?


A. VAR_1234 B. $var_name C. 7VARNAME D. 7var_name

You might also like