Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

150 C++ Bits

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 55

I/O Streams

1. Which operator is used for input stream?

 A. >

 B. >>

2. Where does a cin stops it extraction of data?

 A. By seeing a blankspace

 B. By seeing ()

 C. Both a & b

 D. None of the mentioned

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

 D. None of the mentioned

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

 C. It will print what we give.

 D. None of the mentioned

5. How many parameters are there in getline function?

 A. 1

 B. 2

 C. 3

 D. 4

6. What can be used to input a string with blankspace?

 A. inline

 B. getline

 C. putline

 D. None of the mentioned

When will the cin can start proceessing of input?

 A. After pressing return key

 B. BY pressing blankspace

 C. Both a & b

 D. None of the mentioned

8. How many groups of output of operation are there in c++?

 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

 D. All of the mentioned

10. What is meant by ofstream in c++?

 A. Writes to a file

 B. Reads from a file

 C. Both a & b

 D. None of the mentioned

11.
What is the output of this program?

#include < iostream >


using namespace std;
int main () 
{
char str[] = "Steve jobs";
int val = 65;
char ch = 'A';
cout.width (5);
cout << right;
cout << val << endl;
return 0;
}

 A. Steve jobs

 B. A

 C. 5

 D. 65
12.
What is the output of this program?

#include < iostream >


using namespace std;
int main () 
int n; 
n = 43;
cout << hex << n << endl;
return 0;
}

 A. 2c

 B. 2b

 C. 20

 D. 50

13. How many types of output stream classes are there in c++?

 A. 1

 B. 2

 C. 3

 D. 4

14. What must be specified when we construct an object of class ostream?

 A. stream

 B. streambuf

 C. memory

 D. None of the mentioned

Operators

1. Which operator is having right to left associativity in the following?

 A. Array subscripting
 B. Function call

 C. Addition and subtraction

 D. Type cast

2. Which operator is having the highest precedence?

 A. postfix

 B. unary

 C. shift

 D. equality

3. What is this operator called ?: ?

 A. conditional

 B. relational

 C. casting operator

 D. none of the mentioned

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

5. What is the use of dynamic_cast operator?


 A. it converts virtual base class to derived class

 B. it converts virtual base object to derived objeccts

 C. it will convert the operator based on precedence

 D. None of the mentioned

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

 D. none of the mentioned

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

8. What is the output of this program?


#include < iostream >
using namespace std;
int main ()
{
int x, y;
x = 5;
y = ++x * ++x;
cout << x << y;
x = 5;
y = x++ * ++x;
cout << x << y;
return 0;
}

 A. 749736

 B. 736749

 C. 367497

 D. none of the mentioned

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

 D. none of the mentioned

11. How many sequence of statements are present in c++?

 A. 4

 B. 3

 C. 5

 D. 6

12. The if..else statement can be replaced by which operator?

 A. Bitwise operator

 B. Conditional operator

 C. Multiplicative operator

 D. none of the mentioned


13. The switch statement is also called as?

 A. choosing structure

 B. selective structure

 C. certain structure

 D. none of the mentioned

14. The destination statement for the goto label is identified by what label?

 A. $

 B. @

 C. *

 D. :

15. How many types of loops are there?

 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

 D. all looping processes require that the iterations be known

Arrays

1. Which of the following correctly declares an array?

 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

 B. An array is a series of element

 C. An array is a series of elements of the same type placed in non-contiguous


memory locations

 D. None of the mentioned

4. Which of the following accesses the seventh element stored in array?

 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

 D. None of the mentioned

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

 C. compile time error

 D. garbage value

Pointers

1.
 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

2. The operator used for dereferencing or indirection is ____

 A. *

 B. &

 C. ->

 D. ->>

3.
Choose the right option
     string* x, y;

 A. x is a pointer to a string, y is a string

 B. y is a pointer to a string, x is a string

 C. both x and y are pointer to string types

 D. none of the mentioned

4. Which one of the following is not a possible state for a pointer?

 A. hold the address of the specific object

 B. point one past the end of an object

 C. zero

 D. point to a tye

5. Which of the following is illegal?

 A. int *ip;

 B. string s, *sp = 0;

 C. int i; double* dp = &i;

 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

 B. p now points to b

 C. a is assigned to b

 D. q now points to a

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

 D. it will return some random number

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

 A. int **fun(float**, char**)

 B. int *fun(float*, char*)

 C. int ***fun(float*, char**)

 D. int ***fun(*float, **char)

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

 D. none of the mentioned

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. p is pointer to function.

 B. p is array of pointer to function

 C. p is pointer to such function which return type is array.

 D. p is pointer to array of function. View Answer

12. What is size of generic pointer in c?

 A. 0

 B. 1

 C. 2

 D. Null

13. Void pointer can point to which type of objects?

 A. int

 B. float

 C. double

 D. all of the mentioned

14. When does the void pointer can be dereferenced?

 A. when it doesn’t point to any value

 B. when it cast to another type of object

 C. using delete keyword

 D. none of the mentioned

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++

 B. class member in c++

 C. both a & b

 D. none of the mentioned

17. What we can’t do on a void pointer?

 A. pointer arithemetic

 B. pointer functions

 C. both of the mentioned

 D. none of the mentioned

Constants

1. The constants are also called as

 A. const

 B. preprocessor

 C. literals

 D. none of the mentioned

2. What are the parts of the literal constants?

 A. integer numerals

 B. floating-point numerals

 C. strings and boolean values

 D. all of the mentioned

3. How the constants are declared?

 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

 D. None of the mentioned

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

6. Which of the following statement is true about preprocessor directives?

 A. hese 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

7.
Regarding following statement which of the statements is true?
     const int a = 100;

 A. Declares a variable a with 100 as its initial value

 B. Declares a construction a with 100 as its initial value

 C. Declares a constant a whose value will be 100

 D. Constructs an integer type variable with a as identifier and 100 as value

8. The difference between x and ‘x’ is

 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

 C. Both are same

 D. None of the mentioned

9. How to declare a wide character in string literal?

 A. L prefix

 B. l prefix

 C. W prefix

 D. none of the mentioned

Functions

1. Where does the execution of the program starts?

 A. user-defined function
 B. main function

 C. void function

 D. none of the mentioned

2. What are mandatory parts in function declaration?

 A. return type,function name

 B. return type,function name,parameters

 C. both a and b

 D. none of the mentioned

3. which of the following is used to terminate the function declaration?

 A. :

 B. )

 C. ;

 D. none of the mentioned

4. How many max number of arguments can present in function in c99 compiler?

 A. 99

 B. 90

 C. 102

 D. 127

5. Which is more effective while calling the functions?

 A. call by value

 B. call by reference

 C. call by pointer

 D. none of the mentioned

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

 C. compile time error

 D. none of the mentioned

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

 C. compile time error


 D. none of the mentioned

8. What is the scope of the variable declared in the user definied function?

 A. whole program

 B. only inside the {} block

 C. both a and b

 D. none of the mentioned

9. How many minimum number of functions are need to be presented in c++?

 A. 0

 B. 1

 C. 2

 D. 3

10. How many ways of passing a parameter are there in c++?

 A. 1

 B. 2

 C. 3

 D. 4

11. Which is used to keep the call by reference value as intact?

 A. static

 B. const

 C. absolute

 D. none of the mentioned

12. By default how the value are passed in c++?

 A. call by value

 B. call by reference

 C. call by pointer

 D. none of the mentioned


13. What will happen when we use void in argument passing?

 A. It will not return value to its caller

 B. It will return value to its caller

 C. both a & b are correct

 D. none of the mentioned

14. How many types of returning values are present in c++?

 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

 D. none of the mentioned

17. When will we use the function overloading?

 A. same function name but different number of arguments

 B. different function name but same number of arguments

 C. same function name but same number of arguments

 D. different function name but different number of arguments

18. 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.

19. 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

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

 D. none of the mentioned

21. What are the advantages of passing arguments by reference?

 A. Changes to parameter values within the function also affect the original
arguments.

 B. There is need to copy parameter values (i.e. less memory used)

 C. There is no need to call constructors for parameters (i.e. faster)

 D. All of the mentioned

22. To which does the function pointer point to?

 A. variable

 B. constants

 C. function

 D. absolute variables

23. What we will not do with function pointers?


 A. allocation of memory

 B. de-allocation of memory

 C. both a & b

 D. none of the mentioned

24. What is the default calling convention for a compiler in c++?

 A. __cdecl

 B. __stdcall

 C. __pascal

 D. __fastcall

25. What are the mandatory part to present in function pointers?

 A. &

 B. retrun values

 C. data types

 D. none of the mentioned

26. which of the following can be passed in function pointers?

 A. variables

 B. data types

 C. functions

 D. none of the mentioned

27. What is meaning of following declaration? int(*ptr[5])();

 A. ptr is pointer to function.

 B. ptr is array of pointer to function.

 C. ptr is pointer to such function which return type is array.

 D. ptr is pointer to array of function.

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

 D. none of the mentioned

29. Where does the default parameter can be placed by the user?

 A. leftmost

 B. rightmost

 C. both a & b

 D. none of the mentioned

30. Which value will it take when both user and default values are given?

 A. user value

 B. default value

 C. custom value

 D. none of the mentioned

31. What we can’t place followed by the non-default arguments?

 A. trailing arguments

 B. default arguments

 C. both a & b

 D. none of the mentioned

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

 D. none of the mentioned

33. What is the default return type of a function ?

 A. int

 B. void
 C. float

 D. char

34. Which header file is used to pass unknown number of arguments to function?

 A. stdlib.h

 B. string.h

 C. stdarg.h

 D. none of the mentioned

35. How can you access the arguments that are manipulated in the function?

 A. va_list

 B. arg_list

 C. both a & b

 D. none of the mentioned

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

38. What will initialize the list of arguments in stdarg.h header file?

 A. va_list

 B. va_start
 C. va_arg

 D. none of the mentioned

Namespaces

1. Which operator is used to signify the namespace?

 A. conditional operator

 B. ternary operator

 C. scope operator

 D. none of the mentioned

2. Identify the correct statement

 A. Namespace is used to group class, objects and functions.

 B. Namespace is used to mark the beginning of the program.

 C. Namespace is used to seperate the class, objects.

 D. None of the above

3. What is the use of Namespace?

 A. To encapsulate the data

 B. To structure a program into logical units.

 C. Both a and b

 D. none of the mentioned

4. What is the general syntax for accessing the namespace variable?

 A. namespaceid::operator

 B. namespace,operator

 C. namespace#operator

 D. none of the mentioned

5. Which keyword is used to access the variable in namespace?

 A. using
 B. dynamic

 C. const

 D. static

Classes

1. What does your class can hold?

 A. data

 B. functions

 C. both a & b

 D. none of the mentioned

2. How many specifiers are present in access specifiers in class?

 A. 1

 B. 2

 C. 3

 D. 4

3. How many kinds of classes are there in c++?

 A. 1

 B. 2

 C. 3

 D. 4

4. Which is used to define the member of a class externally?

 A. :

 B. : :

 C. #

 D. none of the mentioned

5. Which other keywords are also used to declare the class other than class?

 A. struct
 B. union

 C. object

 D. both a & b

6. Which of the following is a valid class declaration?

 A. class A { int x; };

 B. class B { }

 C. public class A { }

 D. object A { int x; };

7. The fields in the class in c++ program are by default

 A. protected

 B. private

 C. public

 D. none of the mentioned

8. Constructors are used to

 A. initalize the objects

 B. construct the data members

 C. both a & b

 D. none of the mentioned

9. When struct is used instead of the keyword class means, what will happen in the
program?

 A. access is public by default

 B. access is private by default

 C. access is protected by default

 D. none of the mentioned

10. Which class is used to design the base class?

 A. abstract class

 B. derived class
 C. base class

 D. None of the mentioned

11. Which is used to create a pure virtual function ?

 A. $

 B. =0

 C. &

 D. !

12. Which is also called as abstract class?

 A. virtual function

 B. pure virtual function

 C. derived class

 D. None of the mentioned

13. What is meant by pure virtual function?

 A. Function which does not have definition of its own.

 B. Function which does have definition of its own.

 C. Function which does not have any return type.

 D. None of the mentioned

14. Pick out the correct option.

 A. We cannot make an instance of an abstract base class

 B. We can make an instance of an abstract base class

 C. Both a & b

 D. None of the mentioned

15. Where does the abstract class is used?

 A. base class only

 B. derived class

 C. both a & b
 D. None of the mentioned

16. Where is the derived class is derived from?

 A. derived

 B. base

 C. both a & b

 D. None of the mentioned

17. Pick out the correct statement.

 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.

 D. None of the mentioned

18. Which of the following can derived class inherit?

 A. members

 B. functions

 C. both a & b

 D. None of the mentioned

19. Which operator is used to declare the destructor?

 A. #

 B. ~

 C. @

 D. $

20. Which constructor will initialize the base class data member?

 A. derived class

 B. base class

 C. class

 D. None of the mentioned


21. Which interface decides determines how your class will be used by other program?

 A. public

 B. private

 C. protected

 D. None of the mentioned

22. Pick out the correct statement about override.

 A. Overriding refers to a derived class function that has the same name and
signature as a base class virtual function.

 B. Overriding has different names

 C. both a & b

 D. None of the mentioned

23. How many ways of reusing are there in class hierarchy?

 A. 1

 B. 2

 C. 3

 D. 4

24. How many types of class are there in c++?

 A. 1

 B. 2

 C. 3

 D. 4

25. What will happen when introduce the interface of classes in a run-time polymorphic
hierarchy?

 A. Separation of interface from implementation

 B. Merging of interface from implementation

 C. Separation of interface from debugging

 D. None of the mentioned


26. Which classes are called as mixin?

 A. Represent a secondary design

 B. Classes express functionality which represent responsibilities.

 C. Both a & b

 D. None of the mentioned

27. What is the use of clog?

 A. Standard logging stream

 B. Error stream

 C. Input stream

 D. None of the mentioned

28. How many types of guarantees are there in exception class can have?

 A. 1

 B. 2

 C. 3

 D. 4

29. Which operator is used to create the user-defined streams in c++?

 A. >>

 B. &

 C. Both a & b

30. What does the cerr represent?

 A. Standard error stream

 B. Standard logging stream

 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

 -113 and -114, sum = 227

 -27 and -13, sum = 40

 -11 and -16, sum = -27

2.Select the result of -11 + (-2) in the binary form.

 1110 1101

 1111 1001

 1111 0011

 1110 1001

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

#include <iostream>

using namespace std;

int main() {

int num = 22, result;

result = ~num;

cout << result;

 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>

using namespace std;

int main() {

int a = 10, b = 20, c = 30;

(c > b > a) ? cout << "TRUE" : cout << "FALSE";

 Compilation error

 TRUE

 FALSE

 Unknown result

5.What is the output of the below C++ code?

#include <iostream>

using namespace std;

int main() {

int res;

res = 1000 + 1000 > 1750 ? 400 : 200;

cout << res;

 200

 400

 Compilation error

 1

6. What is the output of the below C++ code?


#include <iostream>

using namespace std;

int main() {

char a = 'A';

char b = 'B';

int c = (int)(a + b % 3 - 3 * 2);

cout << c;

 65

 58

 64

 59

7. What is the output of the below C++ code?

#include <iostream>

using namespace std;

int main() {

short int i = 20;

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>

using namespace std;

int main() {

int a = 3;

float b = 3.0;

if (a == b)

cout << "a and b are equal";

if (a != b)

cout << "a and b are not equal";

 Compilation error

 a and b are equal

 a and b are equal a and b are not equal

 a and b are not equal

Close
9. Select the correct output for the below C++ code when the input is 6?

#include <iostream>

using namespace std;

int main() {

int a, b = 3;

cin >> a;

if (a)

b = a++ - 1;

cout << "a = " << a << endl;

cout << "b = " << b << endl;

}
 a=7
b=5

 a=7
b=6

 a=6
b=6

 a=6
b=5

10. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int x = 5, y = 6;

if (x && !(!x))

cout << "x = " << x;

else

cout << "y = " << y;

 y=6

 x=0

 x=5

 x=1

11. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {
int x = 0;

if (x = 1)

if (x == 0)

printf("inside if");

else

printf("inside else if");

else

printf("inside else");

 inside if

 inside else if

 inside else

 Compilation errors

12. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int i, j;

i = j = 10;

int a = 60, b = 70;

if (a < 100)

if(b > 50)

++i;

else

++j;

cout << "i = " << i << endl;

cout << "j = " << j << endl;

}
 i = 10
j = 10

 i = 11
j = 11

 i = 11
j = 10

 i = 10
j = 11

13. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int i = 1;

switch (i) {

cout << "This is C++ program";

case 1:

cout << "Case-1";

break;

case 2:

cout << "Case-2";

break;

 This is C++ program

 This is C++ program Case-1

 Case-1

 Compilation error
Close
14. Select the correct output in the below C++ code?

#include <iostream>

using namespace std;

int main() {

int choice = -2 ;

switch (choice) {

case -1:

cout << "Case: -1\n";

break;

case -2:

cout << "Case: -2\n";

break;

 Will result in a compilation error.

 Case: -1 Case: -2

 Case: -1

 Case: -2

15. Select the correct output in the below C++ code?

#include <iostream>

using namespace std;

int main() {

int x = 4;

switch (x) {

default:cout << "Given value other than 1, 2 and 3";

break;
case 1: cout << "Given value is 1";

break;

case 2: cout << "Given value is 2";

break;

case 1 + 2: cout << "Given value is 3";

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

 Given value other than 1, 2 and 3

16. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int i = 3;

while (i--) {

int i = 100;

i--;

cout << i << " ";

 99 98 97

 100 99 98
 222

 99 99 99

17. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int a = 6, b = 12;

while (a < b) {

cout << "CodeTantra ";

a+=2;

b-=2;

 CodeTantra CodeTantra

 CodeTantra

 CodeTantra CodeTantra CodeTantra

 Will keep printing CodeTantra infinitely.

Close
18. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int i = 0;

do {
i++;

cout << "Hello CodeTantra";

} while (i < 0);

 Compiletime error

 It does not print anything

 Hello CodeTantra Hello CodeTantra

 Hello CodeTantra

19. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int main() {

int f = 1, i = 2;

do {

f *= i;

} while (++i < 5);

cout << f;

 12

 6

 120

 24

20. Select the output of the below C++ code?


#include <iostream>

using namespace std;

int main() {

int i, j;

for (i = 10; i <= 50; i += 10)

j = i / 2;

cout << j << " ";

 5 10 15 20 25

 20

 Compilation error

 25

21. Select the output of the below C++ code?

#include <iostream>

using namespace std;

int main() {

int n;

for (n = 9; n != 0; n--) {

cout << n-- << " ";

 9753

 97531

 987654321

 It is an infinite loop, continuously printing values starting from 9.


22. Select the output of the below C++ code?

#include <iostream>

using namespace std;

int main() {

int i;

for ( ; ; ) {

cout << "CodeTantra\n";

cout << "C++\n";

 Compiletime error

 Keeps printing CodeTantra infinitely

 Does not print anything

 C++

23. What is the output of the following sample code?

#include <iostream>

using namespace std;

int main() {

int x = 011, i;

for (i = 0; i < x; i+=3) {

cout << "Start ";

continue;

cout << "End ";

 Start Start Start Start


 Start Start End

 Start Start Start

 Compiletime error

24. What is the output of the following sample code?

#include <iostream>

using namespace std;

int main() {

int i = 1;

for ( ; ; ) {

cout << i++ << " ";

if (i > 10)

break;

 It will result in a compilation error as the condition part in the for-loop statement is missing.

 It will result in a compilation error as the break; statement should be enclosed in a loop and not a if condition.

 Program executes printing the value of i infinitely.

 1 2 3 4 5 6 7 8 9 10

25.
How many times would "CodeTantra" get printed?

#include <iostream>

using namespace std;

int main() {

int x;

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

if (x < 5) {
continue;

} else {

break;

cout << "CodeTantra\n";

 10 times

 11 times

 0 times

 Infinite times

26. Select the correct output for the below C code?

#include <iostream>

using namespace std;

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

27. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int sample(int x) {

x++;

return x;

int main() {

int x = 11;

x = sample(x = sample(x = sample(x)));

cout << "Result = " << x << endl;

return 0;

 Result = 11

 Result = 12

 Result = 13

 Result = 14

28. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int test(int i) {

return(i++);
}

int main() {

int i = test(25);

cout << --i;

 Compiletime error

 25

 26

 24

29. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

int i;

int fun1(int);

int fun2(int);

int main() {

int i = 3;

fun1(i);

cout << i << " ";

fun2(i);

cout << i << " ";

int fun1(int j) {

cout << ++j << " ";

return 0;

int fun2(int i) {

cout << ++i << " ";


return 0;

 3344

 4455

 4343

 Compilation error

30. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

void function(const int a = 999) {

cout << a << endl;

int main(){

int x = 10;

cout << x << endl;

function(555);

function();

 10
999
999

 10
555
555

 Compilation error
 10
555
999

31. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

void function1(int a, bool flag = true) {

if (flag == true ) {

cout << "Flag is true and a = " << a;

} else {

cout << "Flag is false and a = " << a;

int main() {

function1(99, false);

return 0;

 Flag is true and a = 9

 Flag is false and a = 99

 Flag is true and a = 99

 Flag is false and a = 9

32. Which of the following mechanism is a static polymorphism?

 Virtual functions

 Dynamic binding

 Inheritance
 Function overloading

33. Which of the following provides a reuse mechanism?

 Abstraction

 Encapsulation

 Inheritance

 Polymorphism

34. Which of the following concepts means wrapping up of data and functions together?

 Abstraction

 Encapsulation

 Inheritance

 Polymorphism

35. Select the correct output for the below C++ code?

#include <iostream>

using namespace std;

struct Time {

int hours;

int minutes;

int seconds;

};

int toSeconds(Time);

int main() {

Time t;

t.hours = 2;

t.minutes = 58;
t.seconds = 27;

cout << "Total seconds: " << toSeconds(t) << endl;

int toSeconds(Time t) {

return 3600 * t.hours + 60 * t.minutes + t.seconds;

 10707

 10000

 Compilation error

 11707

36. What is the default access specifier to the fields of a structure in C++?

 public

 private

 protected

 static

Close
37. Which of the following access specifier is used as default in a class definition?

 public

 private

 protected
 friend

You might also like