CPP Q Bank My Answers
CPP Q Bank My Answers
Question Bank
1. Out of the following, find those identifiers, which cannot be used for naming
Variable, Constants or Functions in a C++ program:
a) Column31
b) _Amount
c) NeW
d) Total*Tax
2. Find the correct identifiers out of the following, which can be used for naming
Variable, Constants or Functions in a C++ program:
a) switch
b) 1stName
c) name1
d) Add+Subtract
void main(){
char *word1="Hello";
cout<<word1;
}
a) ctype
b) iostream
c) math
d) iomanip
4. Observe the following C++ code and write the name(s) of the header file(s),
which will be essentially required to run it in a C++ compiler:
void main( ){
int Number;
Number=-5;
Number =abs(Number);}
a) ctype
b) iostream
c) math
d) iomanip
5. Write the names of the header file to which the setw belong:
a) ctype
b) iostream
c) math
d) iomanip
6. Write the names of the header file to which the isupper( ) belong:
a) ctype
b) iostream
c) math
d) iomanip
7. Observe the following C++ code very carefully and select the line number that has
syntactical error. Note: Assume all required header files are already being
included in the program.
[1] #define SIZE = 100
[2] void main( ){
[3] int x1=6;
[4] if(x1=7) x1=3;}
a) 1
b) 2
c) 3
d) 4
8. Observe the following C++ code very carefully and select the line number that has
syntactical error. Note: Assume all required header files are already being
included in the program.
[1] int main( ){
[2] Double x1=6;
[3] if(7<x1<=2)
[4] x1+=3;}
a) 1
b) 2
c) 3
d) 4
9. …………..variables are those variables which are not declared within any
function or scope. So, these variables can be accessed by any function of the
program.
a) Global
b) Local
c) New
d) General
10. …………..method, the called function creates a new set of variables and copies
the values of arguments into them. The function does not have access to the
original variables (actual parameters) and can only work on the copies of values it
created.
a) Call by reference
b) Call by value
c) Call by pointer
d) Call by vector
12. What is the index number of the last element of an array with 100 elements?
a) 100
b) 99
c) 0
d) Programmer-defined
13. Which of the following accesses the 344th element stored in array?
a) array[343];
b) array[344];
c) array(343);
d) Array(344);
14. Write the output of the following C++ program code. Note: Assume all required
header files are already being included in the program.
int main)({
int const p = 10;
cout << ++p;
return 0;
}
a) 10
b) 11
c) Error
d) None of the mentioned
#include <iostream.h>
main()
{
int n = 4;
cout << n++ <<” “<<++n;
}
a) 4 6
b) 4 5
c) 5 6
d) 6 6
#include <iostream.h>
main() {
int n = 3;
if (n > 3);
{
cout << n * n << “ “;
--n;}
cout << n;
}
a) 3
b) 2
c) 9 2
d) 4 1
22. Which looping process is best used when the number of iterations is known?
a) for
b) while
c) do-while
d) all looping processes require that the iterations be known
24. What is the scope of the variable declared in the user defined function?
a) whole program
b) only inside the {} block
c) both a and b
d) none of the mentioned
26. What will you use if you are not intended to get a return value from a function?
a) static
b) const
c) volatile
d) void
27. When will we use the function overloading?
a) different function name but same number of arguments
b) same function name and same number of arguments
c) different function name and different number of arguments
d) same function name but different number of arguments
32. Which of the following functions will correctly return true if its argument is an
odd integer?
a) bool IsOdd (int x) { return (x / 2 == 1); }
b) bool IsOdd (int x) { if (x % 2 == 0) return true; else return false; }
c) bool IsOdd (int x) { return (x % 2 == 1); }
d) bool IsOdd (int x) { return (x % 2 == 0); }
33. Which of the following functions will correctly swap the contents of the two
integers i and j?
a) void swap (int a, int b) { int temp; temp = a; a = b; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
b) void swap (int &a, int &b) { int temp; temp = a; a = b; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
c) void swap (int a, int b) { int temp; temp = a; b = a; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
d) void swap (int &a, int &b) { int temp; temp = a; b = a; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
35. Compilation is the step in the software development cycle where this type of
errors is detected.
a) logic errors
b) semantics errors
c) specification errors
d) syntax errors
37. What is the value stored in the integer variable intVar? int intVar = 24.2 / 2;
a) 12
b) 12.1
c) 13
d) None of the above
for(int i=0;i<3;i++)
for (int j=0;j<3;j++)
sum++;
a) 2
b) 3
c) 4
d) 9