Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
1 views33 pages

C++ Model Exam

Uploaded by

kadirtadasa412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views33 pages

C++ Model Exam

Uploaded by

kadirtadasa412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

University of Gondar

Institute of Technology
Department of Computer Engineering

Introduction to Computer Programming (C++)


Exit Exam Model Question
1. Which of the following function prototype is perfectly acceptable?
A. int Function(int Tmp = Show());
B. float Function(int Tmp = Show(int, float));
C. float = Show(int, float) Function(Tmp);
D. A and B.
2. Which of the following statement is correct?
A. C++ enables to define functions that take constants as an argument.
B. We cannot change the argument of the function that that are declared as
constant.
C. We cannot use the constant while defining the function.
D. A and B
3. Which of the following statement is correct?
A. Overloaded functions can have at most one default argument.
B. An overloaded function cannot have default argument.
C. All arguments of an overloaded function can be default.
D. A function if overloaded more than once cannot have default argument.
4. Which of the following statement is correct?
A. Two functions having same number of argument, order and type of argument
can be overloaded if both functions do not have any default argument.
B. Overloaded function must have default arguments.
C. Overloaded function must have default arguments starting from the left of
argument list.
1 Prepared By: Sileshi N.
D. A function can be overloaded more than once.
5. Which of the following statement will be correct if the function has three arguments
passed to it?
A. The trailing argument will be the default argument.
B. The first argument will be the default argument.
C. The middle argument will be the default argument.
D. All the argument will be the default argument.
6. Which of the following statement is correct?
A. C++ allows static type checking.
B. C++ allows dynamic type checking.
C. C++ allows static member function be of type const.
D. A and B
7. Which of the following statement is correct?
A. The order of the default argument will be right to left.
B. The order of the default argument will be left to right.
C. The order of the default argument will be alternate.
D. The order of the default argument will be random.
8. Which of the following statement is correct?
A. Only one parameter of a function can be a default parameter.
B. Minimum one parameter of a function must be a default parameter.
C. All the parameters of a function can be default parameters.
D. No parameter of a function can be default.
9. Which of the following statement is correct about the program given below?

#include<iostream.h>

const double BixConstant(const int, const int = 0);


int main()

2 Prepared By: Sileshi N.


{
const int c = 2 ;
cout<< BixConstant(c, 10)<< " ";
cout<< BixConstant(c, 20)<< endl;
return 0;
}
const double BixConstant(const int x, const int y)
{
return( (y + (y * x) * x % y) * 0.2);
}
A. The program will print the output 2 4.
B. The program will print the output 20 40.
C. The program will print the output 10 20.
D. The program will print the output 20 4.50.
E. The program will report compile time error.
10. Which of the following refers to characteristics of an array?

A. An array is a set of distinct data items


B. An array is a set of similar data items
C. An array can hold different types of datatypes
D. None of the above
11. Which of the following statements is correct?
i. We can return a global variable by reference.
ii. We cannot return a local variable by reference.
A. Only i is correct.
B. Only ii is correct.
C. Both i and ii are correct.
D. Both i and ii are incorrect.
12. What will be the output of the following program?

3 Prepared By: Sileshi N.


#include <iostream.h>
enum xyz

{
a, b, c
};
int main()
{
int x = a, y = b, z = c;
int &p = x, &q = y, &r = z;
p = z;
p = ++q;
q = ++p;
z = ++q + p++;
cout<< p << " " << q << " " << z;
return 0;
}

A. 2 3 6
B. 4 4 7
C. 4 5 8
D. 3 4 6
13. Which of the following statement is correct about the program given below?

#include<iostream.h>
int main()
{
int x = 80;
int &y = x;
x++;
cout << x << " " << --y;
return 0;
}

A. The program will print the output 80 80.


B. The program will print the output 81 80.
C. The program will print the output 81 81.
4 Prepared By: Sileshi N.
D. It will result in a compile time error.
14. Which of the following statement is correct about the program given below?

#include<iostream.h>
int main()
{
int x = 80;
int y& = x;
x++;
cout << x << " " << --y;
return 0;
}

A. The program will print the output 80 80.


B. The program will print the output 81 80.
C. The program will print the output 81 81.
D. It will result in a compile time error.
15. Which of the following statement is correct?
A. Once a reference variable has been defined to refer to a particular variable, it
can refer to any other variable.
B. A reference is indicated by using && operator.
C. Once a reference variable has been defined to refer to a particular variable, it
cannot refer to any other variable.
D. A reference can be declared beforehand and initialized later.
16. Which of the following statement is correct about the references?
A. A reference must always be initialized within functions.
B. A reference must always be initialized outside all functions.
C. A reference must always be initialized.
D. A and C.
17. Which of the following gives the 4th element of the array?

5 Prepared By: Sileshi N.


A. Array[0];
B. Array[0];
C. Array[3];
D. None of the above
18. Which of the following statement is incorrect?
A. The default value for an argument can be a global constant.
B. The default arguments are given in the function prototype.
C. Compiler uses the prototype information to build a call, not the function
definition.
D. The default arguments are given in the function prototype and should be
repeated in the function definition.
19. What will be the output of the following program?

#include<iostream.h>
int BixFunction(int a, int b = 3, int c = 3)
{
cout<< ++a * ++b * --c ;
return 0;
}
int main()
{
BixFunction(5, 0, 0);
return 0;
}

A. 8
B. 6
C. -6
D. -8
20. Which of the following header file includes definition of cin and cout?
A. istream.h

6 Prepared By: Sileshi N.


B. ostream.h
C. iomanip.h
D. iostream.h
21. Which of the following function/types of function cannot have default parameters?
A. Member function of class
B. main()
C. Member function of structure
D. Both B and C
22. Which of the following is the correct syntax to add the header file in the C++ program?
A. #include “userdefined.h”
B. #include<userdefined>
C. <include> “userdefined.h”
D. A & B
23. Which of the following is the correct identifier?

1. varname@
2. $var_name
3. VAR_123
4. None of the above
24. 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];
25. Which one of the following represents the tab spacing?

A. \t

7 Prepared By: Sileshi N.


B. \n
C. \r
D. None of the above
26. Which of the following is the address operator?

A. & B. # C. % D. @
27. Which of the following comment syntax is correct to create a single-line comment in
the C++ program?

A. /Comment/
B. Comment//
C. //Comment
D. None of the above
28. Which of the following type casts will convert an Integer variable named amount to a
Double type?
A. (double) amount
B. (int to double) amount
C. int to double(amount)
D. int (amount) to double
29. Which of the following, if any, are valid names for variables?
A. class
B. friend
C. #OnHand
D. void
E. None of the above is valid names for variables
30. You have assigned the address of Value to the pointer P, Which statement will display
the value stored in Value?
A. cout<<P;

8 Prepared By: Sileshi N.


B. cout<<*Value;
C. cout<<<<&P;
D. cout<<*<P;
31. Consider the following program:
#include<iostream>
#include<string>
using namespace std;
int main (){
string str = "This*is^a.45min test.";
int i;
for (i = 0; i < str.length( ); i++) {
if (ispunct(str[i]))
str[i] = ’ ’;// a blank
str[i] = tolower (str[i]); }
cout << str;
}
What does the last line of the code print?
A. this*is^a.45min test.
B. thisisa45mintest
C. this is a 45min test 1. D
D. this is a 45min test.
32. Which of the following functions will correctly return true if its argument is an odd
integer?

9 Prepared By: Sileshi N.


A. II only
B. I and II only
C. I and III only
D. II and III only 4.
E. I, II and III
33. Given below are three implementations of the swap function:

Which of these would actually swap the contents of the two integers i and j?
A. I only
B. II only
C. III only
D. I and II only
E. II and III only
34. What does the following program print?

10 Prepared By: Sileshi N.


A. 0
B. 1
C. The address of b
D. The address of a 7.
E. The address of n
35. Consider this piece of code:

What is the value of x that gets printed by the main?

A. 0 B.1 C.2 D.None of these


36. Consider the following statements:
int *p;
int i, k;
i = 142;
k = i;
p = &i;
Which of the following statements changes the value of i to 143?
11 Prepared By: Sileshi N.
A. k = 143;
B. *k = 143;
C. p = 143;
D. *p = 143;
E. E. More than one of the above
37. Which one of the following is not true about C++ programming language?
A. Dynamically-typed
B. Case sensitive
C. Multi-paradigm
D. Compiled
38. Which of the following is used for comments in C++?
A. //comments
B. */comments/*
C. . /*comments*/
D. A&B
39. Which of the following is valid identifier in C++?
A. var_name7
B. 7var_name
C. $var_name
D. VAR-NAME7
40. Which one is illegal representation of floating-point literals from the following
literals?
A. 3.14159
B. 314159E-5L
C. 510E
D. 510e2

12 Prepared By: Sileshi N.


41. All of the following are Logical Operators except one.
A. && B. || C. ! = D. ^ E. All are Logical Operators
42. In which part of the for loop, the termination condition is checked? for (I; II; III)
A. I B. II C. III D. IV
43. 7. Which of the following is the correct representation of constant declaration in
C++?
A. Using const keyword
B. Using #define keyword
C. Using Static keyword
D. A & B E. A & C
44. Which of the following is a pre-test and post-test loop respectively?
A. while & do-while
B. for &while
C. do-while & for
D. do-while &while
45. 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: " << c;
return 0;
}

A. 2 B. 7 C. 9 D. 14
46. What will be the value of w, x and y respectively.

#include <iostream>
using namespace std;
int main() {
13 Prepared By: Sileshi N.
int x = 10, y = 5;
int w = ++x + y + y--;
return 0;
}
A. 20, 11, 4
B. 21,10,5
C. 21,11,4
D. 20,11, 5
47. What is C++?
A. C++ is an object oriented programming language
B. C++ is a procedural programming language
C. C++ supports both procedural and object oriented programming language
D. C++ is a functional programming language
48. Which of the following symbol is used to declare the preprocessor directives in C++?
A. $ B. ^ C. # D. *
49. One of the methods to stop the execution of the function is by calling the standard
________ function
A. goto
B. jump
C. stop
D. exit
50. Variables that are declared, but not initialized, contain ________
A. blank spaces.
B. zeros.
C. "garbage" values.
D. nothing - they are empty.
51. When a data type must contain decimal numbers, assign the ______ type
A. int

14 Prepared By: Sileshi N.


B. char
C. double
D. long int
52. Which of the following is not an arithmetic operator?
A. + B. * C. – D.&
53. Which of the following will not return a value?
A. null
B. void
C. empty
D. free
54. ___________ is an entry controlled looping statement.
A. for
B. repeat
C. until
D. do..while
55. Which of the following is an exit controlled looping statement
A. for
B. while
C. do..while
D. repeat
56. If the type specifier of parameters of a function is followed by an ampersand (&),
that function call is _______.
A. pass by value.
B. pass by value.
C. array of structures.
D. array of structures. pointers.
57. The general form, of assignment operator is _____.

15 Prepared By: Sileshi N.


A. variable_name=expression
B. datatype=expression.
C. variable=expression.
D. datatype=expression.
58. In flowchart rectangle symbol indicates:
A. Input/Output
B. Connector
C. Process
D. Decision
59. The arithmetic operators are:
A. Ternary operators
B. Unary operators
C. Binary operators
D. None of these
60. In switch structure, each case label may be an integer constant or:
A. Real constant
B. Character constant
C. String constant
D. None of these
61. WHat will be the value of ‘x’ after executing for(x=1;x<=15;x++);?
A. 15 B.1 C.14 D.16
62. The data item of a structured are called:
A. Fields
B. Elements
C. Members
D. All of these

16 Prepared By: Sileshi N.


63. Which of the following strem class is used to perform both input and output file
operation:
A. Ofstream
B. Ifstream
C. fstream
D. iostream
64. Which of the following is a logical operator?
A. = B.!= C.== D.!
65. Which operator is unary operator?
A. .$$ B.>== C.// D.++ E. All of these
66. A relational operator :
A. Compares two operands.
B. assign one operand to another
C. logically combines two operands
D. Adds two operands.
E. none of these
67. Which logical operator is unary operator?
A. // B.! C. && D. Both a and b E. None of the above
68. In following statement which statement are correct?
A. char *X3=”ABC”;
B. char X1[]=”ABC”;
C. char X2[5]=”ABC”;
D. both b and c
E. None of these
69. Statements can only be used inside the body of loop called…

A. if

17 Prepared By: Sileshi N.


B. break

C. countinue

D. switch

70. Processor translates the source code into object code as a whole that is
called_______

A. assembler

B. linker

C. compiler

D. debugge

71. Which of the following is true about header file.

A. definitions of various constants

B. definitions of various data types

C. prototypes of standard library functions

D. All of the above

72. syntax error accur due to…

A. missing semicolon

B. incorrect spelling

C. missing any brace

D. program without declaring

73. A compiler can detect wich type of error

A. logical error

18 Prepared By: Sileshi N.


B. runtime error

C. syntax error

D. all of these

74. which symbols are used for making decision in flowchart….

A. sequence

B. selecion

C. iteration

D. program

75. Which of the following is the not correct statement…

A. char nm[]= ” sundas”;

B. char nm[]= ” sundas”;

C. char nm[15]=”asifa”;

D. char nm=”sawera”;

E. none of these

76. What type of errors will occur in the program when used incorrect of mathematical
formula…

A. syntax error

B. logical error

C. runtime error

D. none of these

77. ………… is an unconditional control transfer statement.

19 Prepared By: Sileshi N.


A. if-else

B. break

C. switch

D. goto

78. Which of the following language is nearest to human language?

A. High level language

B. Low level language

C. C++

D. Both a and c

79. Which of the following language can be run on any platform?

A. High level language

B. Low level language

C. assembly language

D. both b and c

80. Which of the following language needs compiler for translation?

A. High level language

B. C++

C. C#

D. All of these

81. In Which of the following language, all the instructions must be written in order and
the user has to follow the order?

20 Prepared By: Sileshi N.


A. procedural languages
B. non procedural languages
C. object oriented languages
D. None of these
82. Procedure oriented programming basically consists of writing a list of instructions or
actions for the computer to follow and organizing these instructions into groups
known as_______
A. Procedures
B. Functions
C. Flowchart
D. Instructions
83. State whether the following statements are true about object-oriented programming in
C++.
i) Data is hidden and cannot be accessed by external functions.
ii) Follows the top-bottom approach in program design.
iii) Objects may communicate with each other through functions.
A. True, True, False
B. False, True, False
C. True, False, True
D. False, True, True
84. Which statement is used to move the control to the start of loop body?
A. Continue
B. Break
C. Switch
D. None of these
85. In the for statement this expression is executed only once.
A. Test

21 Prepared By: Sileshi N.


B. Validation
C. Initialization
D. None of these
86. Which is true about a variable.
A. The name and data value can be change
B. The name can change but the data value cannot
C. The name cannot change but the data value can
D. None of these
87. Which of the following function / types of function cannot have default parameters?
A. Member function of class
B. Main()
C. Member function of structure
D. Both B and C
88. Which of the following statement is correct?

A. Only one parameter of a function can be a default parameter.


B. Minimum one parameter of a function must be a default parameter.
C. All the parameters of a function can be default parameters.
D. No parameter of a function can be default.
89. Which of the following function declaration using default arguments is incorrect?
A. int foo(int x, int y =5, int z=10)
B. int foo(int x=5, int y =10, int z)
C. int foo(int x=5, int y, int z=10)
D. All are correct
90. What is the output of this program?

Note:Includes all required header files

22 Prepared By: Sileshi N.


using namespace std;

void fun(int p, int q)

p = 20;

q = 10;

int main()

int p = 10;

fun(p, p);

cout << p;

return 0;

A. 10
B. 20
C. compile time error
D. none of the mentioned

91. What is the output of this program?

Note:Includes all required header files


using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}

23 Prepared By: Sileshi N.


int main ()
{
int x = 2, y = 5, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
A. x =3, y =7, z =10
B. x =3, y =6, z =5
C. x =4, y =10, z =14
D. None of the above
92. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int max(int p, int q )
{
return ( p > q ? p : q );
}
int main()
{
int x = 25;
int y = 50;
cout << max(x, y );
return 0;
}

A. 25

B. 50
C. either 25 or 50
D. none of the mentioned

93. What will be the output of the following program?

#include <iostream>
using namespace std;
int lfc (int a, int b)
24 Prepared By: Sileshi N.
{
return (a * b);
}
float lfc (float a, float b)
{
return (a / b);
}
int main()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0;
cout << lfc(x, y) <<" ";
cout << lfc (n, m);
return 0;
}
A. 10.0 5.0
B. 5.0 2.5
C. 10.0 5
D. 10 2.5
94. Which of the following function declaration is/are incorrect?
A. int Sum(int a, int b = 2, int c = 3);
B. int Sum(int a = 5, int b);
C. int Sum(int a = 0, int b, int c = 3);
D. Both B and C are incorrect.
95. A programmer can create custom header files that must be end with
A. .h extension
B. .l extension
C. .ios extension
D. .a extension
96. Choose the correct statements regarding inline functions.
A. It speeds up execution
B. It slows down execution

25 Prepared By: Sileshi N.


C. It increases the code size
D. Both A and C
97. In an assignment statement a=b Which of the following statement is true?
A. The variable a and the variable b are equal.
B. The value of b is assigned to variable a but the later changes on variable b
will not affect the value of variable a
C. The value of b is assigned to variable a and the later changes on variable b
will affect the value of variable a
D. The value of variable a is assigned to variable b and the value of variable b is
assigned to variable a.
98. All of the following are valid expressions in C++ a = 2 + (b = 5); a = b = c = 5;
a = 11 % 3
A. True
B. False
99. 3. To increase the value of c by one which of the following statement is wrong?
A. c++;
B. c = c + 1;
C. c + 1 => c;
D. c += 1
100. When following piece of code is executed, what happens? b = 3; a = b++;
A. a contains 3 and b contains 4
B. a contains 4 and b contains 4
C. a contains 4 and b contains 3
D. a contains 3 and b contains 3
101. The result of a Relational operation is always
A. either True or False
B. is less than or is more than

26 Prepared By: Sileshi N.


C. is equal or less or more
D. All of these
102. Which of the following is not a valid relational operator?
A. == B. => C.>= D.>=
103. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
A. 10 B. 9 C. 0 D. 1
104. When does the code block following while(x<100) execute?
A. When x is less than one hundred
B. When x is greater than one hundred
C. When x is equal to one hundred
D. While it wishes
105. Overloaded functions are
A. Very long functions that can hardly run
B. One function containing another one or more functions inside it.
C. Two or more functions with the same name but different number of
parameters or type.
D. None of the sections
106. The difference between while structure and do structure for looping is
A. In while statement the condition is tested at the end of first iteration
B. In do structure the condition is tested at the beginning of first iteration
C. The do structure decides whether to start the loop code or not whereas while
statement decides whether to repeat the code or not
D. In while structure condition is tested before executing statements inside loop
whereas in do structure condition is tested before repeating the statements
inside loop
107. Which of the following is not a jump statement in C++?
A. break

27 Prepared By: Sileshi N.


B. goto
C. exit
D. switch
108. The continue statement
A. resumes the program if it is hanged
B. resumes the program if it was break was applied
C. skips the rest of the loop in current iteration
D. all of above
109. If you use same variable for two getline statements
A. Both the inputs are stored in that variable
B. The second input overwrites the first one
C. The second input attempt fails since the variable already got its value
D. You cannot use same variable for two getline statements
110. Identify the correct statement regarding scope of variables
A. Global variables are declared in a separate file and accessible from any
program.
B. Local variables are declared inside a function and accessible within the
function only.
C. Global variables are declared inside a function and accessible from anywhere
in program.
D. Local variables are declared in the main body of the program and accessible
only from functions.
111. An array element is accessed using
A. FIFO approach
B. An index number
C. A member name
D. By the iterator/operator

28 Prepared By: Sileshi N.


112. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++){
result += array[n];
}
cout << result;
return 0;
}
A. 25
B. 26
C. 27
D. 21

113. What will be the values of x, m and n after the execution of the following
statements?
int x, m, n;
m= 10;
n= 15;
x = ++m + n++;
A. x=25, m=10, n=15
B. x=26, m=11, n=16
C. x=27, m=11, n=16
D. x=27, m=10, n=15
114. Which can be passed as an argument to a function?
A. Constant
B. Expression
C. Another function
D. All of the above
119. What is an inline function?
A. A function that is expanded at each call during execution
B. A function that is called during compile time

29 Prepared By: Sileshi N.


C. A function that is not checked for syntax errors
D. A function that is not checked for semantic analysis
120. Which of the following is important in a function?
A. Return type
B. Function name
C. Both return type and function name
D. The return type, function name and parameter list
121. Where does the execution of the program starts?
A. user-defined function
B. main function
C. void function
D. else function
122. What are mandatory parts in the function declaration?
A. return type, function name
B. return type, function name, parameters
C. parameters, function name
D. parameters, variables
123. When we define the default values for a function?
A. When a function is defined
B. When a function is declared
C. When the scope of the function is over
D. When a function is called
124. If an argument from the parameter list of a function is defined constant then ___
A. It can be modified inside the function
B. It cannot be modified inside the function
C. Error occurs
D. Segmentation fault

30 Prepared By: Sileshi N.


125. What will be used when terminating a structure?
A. : B. } C. ; D. ;;
126. What will be the output of the following C++ code?
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int student{
int num;
char name[25];
}
student stu;
stu.num = 123;
strcpy(stu.num, "john");
cout << stu.num << endl;
cout << stu.name << endl;
return 0;
}
A. 123
john
B. john
john
C. compile time error
D. runtime error

127. Which of the following is a properly defined structure?

A. struct {int a;}


B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};

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

31 Prepared By: Sileshi N.


#include <iostream>
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

129. What does the following statement mean?

int (*fp) (char*);

A. pointer to a pointer
B. pointer to an array of chars
C. pointer to function taking a char* argument and returns an int
D. function taking a char* argument and returning a pointer to int

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


#include <iostream>
using namespace std;
int main() {
char arr[20];
int i;
for (i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
32 Prepared By: Sileshi N.
cout << arr;

return 0;
}
A. ABCDEFGHIJ
B. AAAAAAAAAA
C. JJJJJJJJ
D. AAAAAAJJJJ

131. What is the meaning of the following declaration?


int (*p [5]) ();

A. p is pointer to function
B. p is array of pointer to function
C. p is pointer to such function which return type is the array
D. p is pointer to array of function

N.B: TRY THESE QUESTIONS AND STUDY BASED ON SUCH MANNER.

NO GOOD LUCK, ONLY HARD WORK.

33 Prepared By: Sileshi N.

You might also like