150 C++ Bits
150 C++ Bits
150 C++ Bits
A. >
B. >>
B. By seeing ()
C. Both a & b
3.
What is the output of this program?
#include < iostream >
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i + 4;
return 0;
}
A. 73
B. your value + 4
C. Error
4.
What is the output of this program?
#include < iostream >
using namespace std;
int main( )
{
char line[100];
cin.getline( line, 100, 't' );
cout << line;
return 0
}
A. 100
B. t
A. 1
B. 2
C. 3
D. 4
A. inline
B. getline
C. putline
C. Both a & b
A. 1
B. 2
C. 3
D. 4
9. Pick out the correct objects about the instantiation of output stream.
A. cout
B. cerr
C. clog
A. Writes to a file
C. Both a & b
11.
What is the output of this program?
A. Steve jobs
B. A
C. 5
D. 65
12.
What is the output of this program?
A. 2c
B. 2b
C. 20
D. 50
A. 1
B. 2
C. 3
D. 4
A. stream
B. streambuf
C. memory
Operators
A. Array subscripting
B. Function call
D. Type cast
A. postfix
B. unary
C. shift
D. equality
A. conditional
B. relational
C. casting operator
4.
What is the output of this program?
#include
using namespace std;
int main()
{
int a;
a = 5 + 3 * 5;
cout << a;
return 0;
}
A. 35
B. 20
C. 25
D. 30
6.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 6, c, d;
c = a, b;
d = (a, b);
cout << c << 't' << d;
return 0;
}
A. 5 6
B. 6 5
C. 6 7
7.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout << i;
return 0;
}
A. 1000
B. 11
C. 1010
D. 1001
A. 749736
B. 736749
C. 367497
9.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 6, c;
c = (a > b) ? a : b;
cout << c;
return 0;
}
A. 6
B. 5
C. 4
D. 7
10.
What is the output of this program?
#include < iostream >
using namespace std;
main()
{
double a = 21.09399;
float b = 10.20;
int c ,d;
8. c = (int) a;
d = (int) b;
cout << c <<'t'<< d;
return 0;
}
A. 20 10
B. 10 21
C. 21 10
A. 4
B. 3
C. 5
D. 6
A. Bitwise operator
B. Conditional operator
C. Multiplicative operator
A. choosing structure
B. selective structure
C. certain structure
14. The destination statement for the goto label is identified by what label?
A. $
B. @
C. *
D. :
A. 4
B. 2
C. 3
D. 1
16. Which looping process is best used when the number of iterations is known?
A. for
B. while
C. do-while
Arrays
A. int array[10];
B. int array;
C. array{10};
D. array array[10];
2. What is the index number of the last element of an array with 9 elements?
A. 9
B. 8
C. 0
D. Programmer-defined
3. What is a array?
A. n array is a series of elements of the same type in contiguous memory locations
A. array[6];
B. array[7];
C. array(7);
D. array;
5. Which of the following gives the memory address of the first element in array?
A. array[0];
B. array[1];
C. array(2);
D. array;
6.
What is the output of this program?
#include < stdio.h >
using namespace std;
int main()
{
char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
}
A. ABC
B. ABCD
C. AB
7.
What is the output of this program?
#include < stdio.h >
using namespace std;
int main()
{
int array[] = {10, 20, 30};
cout << -2[array];
return 0;
}
A. -15
B. -30
D. garbage value
Pointers
1.
What does the following statement mean?
int (*fp)(char*)
A. pointer to a pointer
A. *
B. &
C. ->
D. ->>
3.
Choose the right option
string* x, y;
C. zero
D. point to a tye
A. int *ip;
B. string s, *sp = 0;
D. int *pi = 0;
6.
What will happen in this code?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;
A. b is assigned to a
C. a is assigned to b
7.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}
A. 5
B. 10
C. 15
8. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a
char and returns a pointer to a pointer to a integer is
9.
What is the output of this program?
#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';
cout << arr;
return(0);
}
A. ABCDEFGHIJ
B. AAAAAAAAAA
C. JJJJJJJJ
10.
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}
A. fg
B. cdef
C. defg
D. abcd
11.
What is meaning of following declaration?
int(*p[5])();
A. 0
B. 1
C. 2
D. Null
A. int
B. float
C. double
15. The pointer can point to any variable that is not declared with which of these?
A. const
B. volatile
C. both a & b
D. static
16. A void pointer cannot point to which of these?
A. methods in c++
C. both a & b
A. pointer arithemetic
B. pointer functions
Constants
A. const
B. preprocessor
C. literals
A. integer numerals
B. floating-point numerals
A. const keyword
B. #define preprocessor
C. both a and b
D. None of the mentioned
4.
What is the output of this program?
#include
using namespace std;
int main()
{
int const p = 5;
cout << ++p;
return 0;
}
A. 5
B. 6
C. Error
5.
What is the output of this program?
#include < iostream >
using namespace std;
#define PI 3.14159
int main ()
{
float r = 2;
float circle;
circle = 2 * PI * r;
cout << circle;
return 0;
}
A. 12.566
B. 13.566
C. 10
D. compile time error
7.
Regarding following statement which of the statements is true?
const int a = 100;
A. The first one refers to a variable whose identifier is x and the second one refers to
the character constant x
B. The first one is a character constant x and second one is the string literal x
A. L prefix
B. l prefix
C. W prefix
Functions
A. user-defined function
B. main function
C. void function
C. both a and b
A. :
B. )
C. ;
4. How many max number of arguments can present in function in c99 compiler?
A. 99
B. 90
C. 102
D. 127
A. call by value
B. call by reference
C. call by pointer
6.
What is the output of this program?
#include < iostream >
using namespace std;
void mani()
void mani()
{
cout << "hai";
}
int main()
{
main();
return 0;
}
A. hai
B. haihai
7.
What is the output of this program?
#include < iostream >
using namespace std;
void fun(int x, int y)
{
x = 20;
y = 10;
}
int main()
{
int x = 10;
fun(x, x);
cout << x;
return 0;
}
A. 10
B. 20
8. What is the scope of the variable declared in the user definied function?
A. whole program
C. both a and b
A. 0
B. 1
C. 2
D. 3
A. 1
B. 2
C. 3
D. 4
A. static
B. const
C. absolute
A. call by value
B. call by reference
C. call by pointer
A. 1
B. 2
C. 3
D. 4
15. What will you use if you are not intended to get a return value?
A. static
B. const
C. volatile
D. void
16. Where does the return statement returns the execution of the program?
A. main function
B. caller function
C. same function
C. Two or more functions with the same name but different number of parameters or
type.
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)
20. When our function doesn’t need to return anything means what we will as parameter in
function?
A. void
B. blank space
C. both a & b
A. Changes to parameter values within the function also affect the original
arguments.
A. variable
B. constants
C. function
D. absolute variables
B. de-allocation of memory
C. both a & b
A. __cdecl
B. __stdcall
C. __pascal
D. __fastcall
A. &
B. retrun values
C. data types
A. variables
B. data types
C. functions
28. If the user didn’t supply the user value means, then what value will it take?
A. default value
B. rise an error
C. both a & b
A. leftmost
B. rightmost
C. both a & b
30. Which value will it take when both user and default values are given?
A. user value
B. default value
C. custom value
A. trailing arguments
B. default arguments
C. both a & b
32. If we start our function call with default arguments means, what will be proceeding
arguments?
A. user argument
B. empty arguments
C. default arguments
A. int
B. void
C. float
D. char
A. stdlib.h
B. string.h
C. stdarg.h
35. How can you access the arguments that are manipulated in the function?
A. va_list
B. arg_list
C. both a & b
36. What is the maximum number of arguments or parameters that can be present in one
function call?
A. 64
B. 256
C. 255
D. 16
37. Which header file should you include if you are to develop a function that can accept
variable number of arguments?
A. varag.h
B. stdlib.h
C. stdio.h
D. stdarg.h
A. va_list
B. va_start
C. va_arg
Namespaces
A. conditional operator
B. ternary operator
C. scope operator
C. Both a and b
A. namespaceid::operator
B. namespace,operator
C. namespace#operator
A. using
B. dynamic
C. const
D. static
Classes
A. data
B. functions
C. both a & b
A. 1
B. 2
C. 3
D. 4
A. 1
B. 2
C. 3
D. 4
A. :
B. : :
C. #
5. Which other keywords are also used to declare the class other than class?
A. struct
B. union
C. object
D. both a & b
A. class A { int x; };
B. class B { }
C. public class A { }
D. object A { int x; };
A. protected
B. private
C. public
C. both a & b
9. When struct is used instead of the keyword class means, what will happen in the
program?
A. abstract class
B. derived class
C. base class
A. $
B. =0
C. &
D. !
A. virtual function
C. derived class
C. Both a & b
B. derived class
C. both a & b
D. None of the mentioned
A. derived
B. base
C. both a & b
A. A derived class’s constructor cannot explicitly invokes its base class’s constructor.
B. A derived class’s destructor cannot invoke its base class’s destructor.
C. A derived class’s destructor can invoke its base class’s destructor.
A. members
B. functions
C. both a & b
A. #
B. ~
C. @
D. $
A. derived class
B. base class
C. class
A. public
B. private
C. protected
A. Overriding refers to a derived class function that has the same name and
signature as a base class virtual function.
C. both a & b
A. 1
B. 2
C. 3
D. 4
A. 1
B. 2
C. 3
D. 4
25. What will happen when introduce the interface of classes in a run-time polymorphic
hierarchy?
C. Both a & b
B. Error stream
C. Input stream
28. How many types of guarantees are there in exception class can have?
A. 1
B. 2
C. 3
D. 4
A. >>
B. &
C. Both a & b
C. Input stream
D. Output stream
1.Given two numbers in their binary form: 11110010 and 11110011.Determine their decimal representation along with their sign
and result of their sum.
-14 and -13, sum = -27
1110 1101
1111 1001
1111 0011
1110 1001
#include <iostream>
int main() {
result = ~num;
65513
-23
-22
The code will result in compilation error, because we cannot use ~ operator in the statement result = ~num;
4.What is the output of the below C++ code?
#include <iostream>
int main() {
Compilation error
TRUE
FALSE
Unknown result
#include <iostream>
int main() {
int res;
200
400
Compilation error
1
int main() {
char a = 'A';
char b = 'B';
cout << c;
65
58
64
59
#include <iostream>
int main() {
char c = 97;
cout << sizeof(i) << " " << sizeof(c) << " " << sizeof(c + i);
return 0;
212
112
214
228
8. Select the correct output for the below C++ code?
#include <iostream>
int main() {
int a = 3;
float b = 3.0;
if (a == b)
if (a != b)
Compilation error
Close
9. Select the correct output for the below C++ code when the input is 6?
#include <iostream>
int main() {
int a, b = 3;
cin >> a;
if (a)
b = a++ - 1;
}
a=7
b=5
a=7
b=6
a=6
b=6
a=6
b=5
#include <iostream>
int main() {
int x = 5, y = 6;
if (x && !(!x))
else
y=6
x=0
x=5
x=1
#include <iostream>
int main() {
int x = 0;
if (x = 1)
if (x == 0)
printf("inside if");
else
else
printf("inside else");
inside if
inside else if
inside else
Compilation errors
#include <iostream>
int main() {
int i, j;
i = j = 10;
if (a < 100)
++i;
else
++j;
}
i = 10
j = 10
i = 11
j = 11
i = 11
j = 10
i = 10
j = 11
#include <iostream>
int main() {
int i = 1;
switch (i) {
case 1:
break;
case 2:
break;
Case-1
Compilation error
Close
14. Select the correct output in the below C++ code?
#include <iostream>
int main() {
int choice = -2 ;
switch (choice) {
case -1:
break;
case -2:
break;
Case: -1 Case: -2
Case: -1
Case: -2
#include <iostream>
int main() {
int x = 4;
switch (x) {
break;
case 1: cout << "Given value is 1";
break;
break;
return 0;
Will result in a compilation error, because the default case is written in the beginning and not at the end of
the switch-case block.
Will result in a compilation error, because the last case case 1 + 2: is an illegal constant-expression.
Given value is 3
#include <iostream>
int main() {
int i = 3;
while (i--) {
int i = 100;
i--;
99 98 97
100 99 98
222
99 99 99
#include <iostream>
int main() {
int a = 6, b = 12;
while (a < b) {
a+=2;
b-=2;
CodeTantra CodeTantra
CodeTantra
Close
18. Select the correct output for the below C++ code?
#include <iostream>
int main() {
int i = 0;
do {
i++;
Compiletime error
Hello CodeTantra
#include <iostream>
int main() {
int f = 1, i = 2;
do {
f *= i;
cout << f;
12
6
120
24
int main() {
int i, j;
j = i / 2;
5 10 15 20 25
20
Compilation error
25
#include <iostream>
int main() {
int n;
for (n = 9; n != 0; n--) {
9753
97531
987654321
#include <iostream>
int main() {
int i;
for ( ; ; ) {
Compiletime error
Keeps printing CodeTantra infinitely
C++
#include <iostream>
int main() {
int x = 011, i;
continue;
Compiletime error
#include <iostream>
int main() {
int i = 1;
for ( ; ; ) {
if (i > 10)
break;
It will result in a compilation error as the break; statement should be enclosed in a loop and not a if condition.
1 2 3 4 5 6 7 8 9 10
25.
How many times would "CodeTantra" get printed?
#include <iostream>
int main() {
int x;
if (x < 5) {
continue;
} else {
break;
10 times
11 times
0 times
Infinite times
#include <iostream>
int result(int x) {
if (x % 2)
return 0;
else
return 1;
int main() {
int x = 3;
x = result(x);
x = result(x);
cout << x;
1
0
Compilation error
No result
#include <iostream>
int sample(int x) {
x++;
return x;
int main() {
int x = 11;
return 0;
Result = 11
Result = 12
Result = 13
Result = 14
#include <iostream>
int test(int i) {
return(i++);
}
int main() {
int i = test(25);
Compiletime error
25
26
24
#include <iostream>
int i;
int fun1(int);
int fun2(int);
int main() {
int i = 3;
fun1(i);
fun2(i);
int fun1(int j) {
return 0;
int fun2(int i) {
3344
4455
4343
Compilation error
#include <iostream>
int main(){
int x = 10;
function(555);
function();
10
999
999
10
555
555
Compilation error
10
555
999
#include <iostream>
if (flag == true ) {
} else {
int main() {
function1(99, false);
return 0;
Virtual functions
Dynamic binding
Inheritance
Function overloading
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction
Encapsulation
Inheritance
Polymorphism
#include <iostream>
struct Time {
int hours;
int minutes;
int seconds;
};
int toSeconds(Time);
int main() {
Time t;
t.hours = 2;
t.minutes = 58;
t.seconds = 27;
int toSeconds(Time t) {
10707
10000
Compilation error
11707
public
private
protected
static
Close
37. Which of the following access specifier is used as default in a class definition?
public
private
protected
friend