You are on page 1of 100

Cid Syid Qname

3 2 Constant variables can be created in CPP by using ________ .


3 2 Object oriented programming employs_________ programming approach.
3 2 In CPP, cin and cout are the predefined stream __________ .
3 2 _________________are used for generic programming.
3 2 Can a class be declared/defined inside another class ?
3 3 Which of the header file must be included to use stringstream?
3 3 Which of the following header file does not exist?
3 3 If you use same variable for two getline statements
3 3 The “return 0;” statement in main function indicates
3 3 Which of the following is not a reserve keyword in C++?
3 3 The size of following variable is not 4 bytes in 32 bit systems
3 4 Which one is suitable syntax for function template?
3 4 A class can contain objects of other classes and this phenomenon is called_________
3 4 While redefining a virtual function in the derived class, if its prototype is changed then _

Object based language differs from object oriented lang


uage as it does not support features _____ .
<pre>
1. Encapsulation
2. Inheritance
3. Dynamic Binding
4. Abstraction
3 4 5. Polymorphism </pre>
3 4 Classes in CPP are________ .

<b>Which of the followings is/are not keyword/s in CPP?</b>


<pre>
1. asm
2. boolean
3. mutable
4. export
3 4 5. constant_cast </pre>
3 5 Lines, rectangles and circles are
3 5 There is no close match exist between programming constructs and it
3 5 In an economical model, physical object is
3 5 Element of computer-user environment is

Data structure in which a record is linked to two


successor records, usually referred to as the lef
branch when greater and the right when less
3 5 the previous record is termed as
3 6 In the following declaration, what is the return type?int myMethod(int count, double valu

3 6 In the following function declaration, what is the name of the m


In the following functiondeclaration, how many formal pa
rameters are there?double squareRoot(double value) { return
3 6 2.3;}
In the following function how many values are returned?voi
3 6 d syncPhone(int idNumber) {}

The following code in the


main is valid:void createGameCharacter
() {}int main(int argc, char *argv[]) { int value; value =
3 6 createGameCharacter(); // rest of program}
3 7 Static variable in a class is initialized when _____ .
3 7 By default, members of the class are ____________ in nature.
3 7 Default value of static variable is_____ .
3 7 ________ are used to format the data display in CPP.
3 7 Which of the following is CPP style type-casting?
If a program uses Inline Function, then the func
3 7 tion is expanded inline at ___________.

<b>// Assume that integers take 4 bytes.</b>


<pre>
#include<iostream>

using namespace std;


class Test
{
static int i;
int j;
};

int Test::i;

int main()
{
cout << sizeof(Test);
return 0;
3 8 }</pre>
<pre>
#include<iostream>

using namespace std;


class Base1 {
public:
Base1()
{ cout << " Base1's constructor called" << endl; }
};

class Base2 {
public:
Base2()
{ cout << "Base2's constructor called" << endl; }
};

class Derived: public Base1, public Base2 {


public:
Derived()
{ cout << "Derived's constructor called" << endl; }
};

int main()
{
Derived d;
return 0;
}
3 8 </pre>
<pre>
#include<iostream>
using namespace std;

class base {
int arr[10];
};

class b1: virtual public base { };

class b2: virtual public base { };

class derived: public b1, public b2 {};

int main(void)
{
cout<<sizeof(derived);
getchar();
return 0;
}
3 8 </pre>

<pre>
#include<iostream>
using namespace std;

class base {
int arr[10];
};

class b1: public base { };

class b2: public base { };

class derived: public b1, public b2 {};

int main(void)
{
cout<<sizeof(derived);
getchar();
return 0;
</pre>
3 8
<pre>
#include<iostream>
#include<stdio.h>
using namespace std;

class Base
{
public:
Base()
{
fun(); //note: fun() is virtual
}
virtual void fun()
{
cout<<"\nBase Function";
}
};

class Derived: public Base


{
public:
Derived(){}
virtual void fun()
{
cout<<"\nDerived Function";
}
};

int main()
{
Base* pBase = new Derived();
delete pBase;
return 0;
3 8 }</pre>
<pre>
#include<iostream>
using namespace std;

int x = 10;
void fun()
{
int x = 2;
{
int x = 1;
cout << ::x << endl;
}
}

int main()
{
fun();
return 0;
}
3 8 </pre>

<pre>
#include <iostream>

using namespace std;

int main( ) {
char sample[] = "GeeksforGeeks";

cout << sample << " - A computer science portal for geeks";
return 0;
}
3 9 </pre>
<pre>
#include<iostream>
using namespace std;

int main()
{
int age;

cout << "Enter your age:";


cin >> age;
cout << "\nYour age is: "<<age;
return 0;
}
3 9 </pre>

<pre>#include <iostream>

using namespace std;

int main( )
{
cerr << "An error occured";

return 0;
}
3 9 </pre>

<pre>#include <iostream>
using namespace std;

int main( )
{
clog << "An error occured";

return 0;
}
3 9 </pre>

3 9 Which header file is used with input and output operations of C in C++?
3 9 Which will be used with physical devices to interact from C++ program
3 9 What is the benefit of c++ input and output over c input and output?
3 10 Which best describes a variable?
3 10 Which of the following is false?
3 10 To use the value of a variable you need to know:
3 10 Which of the following data types CANNOT store the number 47,255?
3 10 In C++ the syntax to declare a variable is:
3 10 Which holds integers or real numbers with 8 bytes of memory allocated?
3 10 Which holds alphanumerics using character encoding? (size varies)
3 10 Which holds whole numbers? (4 bytes)
3 11 What is the size of wchar_t in C++
3 11 Pick the odd one out
3 11 Which datatype is used to represent the absence of parameters?
3 11 What does a escape code represent?
3 11 Which type is best suited to represent the logical values?
3 11 Identify the user-defined types from the following?
Which of the following statements are true?
3 11 int f(float)
3 11 The value 132.54 can represented using which data type?
3 12 Which operator is having right to lef associativity in the following?
3 12 Which operator is having the highest precedence?
3 12 What is this operator called ?: ?

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
int main()
{
int a;
a = 5 + 3 * 5;
cout << a;
return 0;
3 12 }</pre>
3 12 What is the use of dynamic_cast operator?

<b> What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 6, c;
c = (a > b) ? a : b;
cout << c;
return 0;
3 12 }</pre>
<b>What is the output of this program?</b>
<pre>
#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;
3 12 }</pre>

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
int main()
{
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout << i;
return 0;
3 12 }</pre>

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 6, c, d;
c = a, b;
d = (a, b);
cout << c << ' ' << d;
return 0;
3 12 }</pre>
3 14 Which of the following is true?
3 14 Which of the following is the boolean operator for logical-and?
3 14 Evaluate !(1 && !(0 || 1)).
3 14 Which of the following shows the correct syntax for an if statement?
3 14
3 14
3 14
3 15 In a switch statement what must come after every case?
3 15 Can cases have conditions?
3 15 What is wrong with this? case (x > 2):
3 15 What is wrong with this? case 2:
3 15 True or false, cases must have curly braces like if statemen
3 16 Which one is not a loop?
3 16 What loop needs a semi colon after?
3 16 Which for loop is correct?
3 16 What loops will always execute at least once?
3 16 which for loop will not work?
3 16 Does every loop require curly braces?
3 16 What loop requires curly braces?
3 16 Which loop is correct?

<pre>
Consider the following code:
var i = 0;
while (i < 3) {
println("hi");
i++;
}
println("bye");</pre>
3 17 <b>What does the code output?</b>

<pre>
Consider the following code:
var i = 0;
while (i < 0) {
println("hi");
}</pre>
3 17 <b>What does the code output?</b>

<pre>
Consider the following code:
var x = 3;
var i = 0;
while (i < 3) {
x += 1;
i += 1;
}
println(x);</pre>
3 17 <b>What does the code output?</b>
<pre>
Consider the following code:
var i = 3;
while (i < 6) {
println(i);
i += 1;
}</pre>
3 17 <b>What does the code output?</b>

<pre>
Consider the following code:
var i = 0;
while (i < 3) {
println(i);
i++;
}</pre>
3 17 <b>What does the code output?</b>

<b>What is the value of m when you exit the loop?</b>


<pre>
for(int m=30; m>0; m=m-4)

out.println(m);

3 18 }</pre>

<b>What is the output?</b>


<pre>
int total=0;
for(int s=1; s<15; s++)

total=total+s;

3 18 out.println(total);</pre>
What is the output?

int z=2, sum=0;

while(z<9)

z++;

sum=sum+z;

3 18 System.out.print(sum);</pre>

<b>What is the output?</b>


<pre>
int k=3;

String s="";

while(k>-1){

s=k+" "+s;

k--;

3 18 System.out.print(s);</pre>
<b>What is the output?</b>
<pre>
int b=5;

String list="";

while(b<11)

b=b+2;

if(b%2==1)

list=b+" "+list;

3 18 System.out.print(list);</pre>

<b>What is the output?</b>


<pre>
int x=1;

do{

x++;

System.out.print(x);

3 18 }while(x<5);</pre>

<b>What is the output?</b>


<pre>
int k=3, tot=0;

do{

tot=tot+k;

k++;

}while(k<11);

3 18 System.out.print(tot);</pre>
3 19 The break statement is used in
3 19 The statements that causes the control program to jump over the other state
3 19 Destination is specified by a label within the statement, is called
3 19 Which from the following is a jumping statement?
An error that causes the program to terminate immediately without having
3 19 successfully performed its job, is called
3 19 An object whose value cannot be changed is called
3 19 In 1977, Apple Computer popularized the phenomenon of
3 19 Keywords are also called
3 19 Which keyword can be used for coming out of recursion?
3 19 The keyword ‘break’ cannot be simply used within:

3 20 Continue statement used for


3 20 Which operator in c can't be overloaded

Continue statement used for


3 20
3 20 calloc() belongs to which library
3 20 printf() belongs to which library of c
3 20 What is the purpose of getc()
3 21 The label in Goto statement is same like
3 21 The imprudent use of Goto statement leads to the

<b>What is the output of the code given below?</b>


<pre>
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
3 21 }</pre>

<b> What is the output of code given below?</b>


<pre>
#include <stdio.h>
int main()
{
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
3 21 }</pre>
<b>What is the output of code given below?</b>
<pre>
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
}
void foo()
{
l1 : printf("3 ", 3);
3 21 }</pre>
3 22 How many types of comments are there in c++?
3 22 What is a comment in c++?
3 22 What type of comments does c++ support?

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
int main()
{
/* this is comment*
cout << "hello world";
return 0;
}</pre>
3 22
3 22 What is used to write multi line comment in c++?
3 22 What is the use of the indentation in c++?
3 22 What will happen when we use void in argument passing?
3 24 When using a function, what is the first thing you must do?
3 24 Where should the prototype be?
3 24 Here is a function, double numbers (int x), what is the name
3 24 From question 3, what data type will this function return?
3 24 From question 4, what data type will this function take in?
3 24 int my_function (double a), what type of data will this func
Say we have a function, double subtract (double x,
double y), what is the correct way to call this function in
the
3 24 main program?
3 24 If a variable is declared inside a function, what kind of vari
If we have a function int stop (int n) , are we able to
send it a different variable in the main program or does it
have to be n.
3 24 For example, stop (x)
3 25 How many ways of passing a parameter are there in c++?
3 25 Which is used to keep the call by reference value as intact?
3 25 By default how the value are passed in c++?

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
3 25 }</pre>

<b>What is the new value of x?</b>


<pre>
#include <iostream>
using namespace std;
void fun(int &x)
{
x = 20;
}
int main()
{
int x = 10;
fun(x);
cout << "New value of x is " << x;
return 0;
3 25 }</pre>
<b>What is the output of this program?</b>
<pre>
#include <iostream>
using namespace std;
long factorial (long a)
{
if (a > 1)
return (a * factorial (a + 1));
else
return (1);
}
int main ()
{
long num = 3;
cout << num << "! = " << factorial ( num );
return 0;
3 25 }</pre>

<b>What is the output of this program?</b>


<pre>
#include <iostream>
using namespace std;
void square (int *x)
{
*x = (*x + 1) * (*x);
}
int main ( )
{
int num = 10;
square(&num);
cout << num;
return 0;
3 25 }</pre>
<b>What is the output of this program?</b>
<pre>
#include <iostream>
using namespace std;
int add(int a, int b);
int main()
{
int i = 5, j = 6;
cout << add(i, j) << endl;
return 0;
}
int add(int a, int b )
{
int sum = a + b;
a = 7;
return a + b;
3 25 }</pre>
3 25 What will happen when we use void in argument passing?
3 26 Recursion is a method in which the solution of a problem depends o
3 26 Which of the following problems can be solved using recursion?
3 26 Recursion is similar to which of the following?
3 26 In recursion, the condition for which the function will stop calling itse

<b>Consider the following code snippet:</b>


<pre>
void my_recursive_function()
{
my_recursive_function();
}
int main()
{
my_recursive_function();
return 0;
3 26 }</pre>
<b>What is the output of the following code?</b>
<pre>
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
3 26 }</pre>

<b> What is the base case for the following code?</b>


<pre>
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
3 26 }</pre>

<b>How many times is the recursive function called, when the


following code is executed?</b>
<pre>
void my_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}
</pre>
3 26
3 26 Which of the following statements is true?
3 27 Which from following is not a storage class specifier in C++?
3 27 An identifier's storage class determines
3 27 How many storage classes specifies are offered by C++?
3 27 Which of the following is not a storage class specifier in C++
A1
enum
top-down
Operator
Inheritance
Yes
<iostream>
<iostream>
Both the inputs are stored in that variable
 The program did nothing; completed 0 tasks
  mutable
 int
template< class T> return_type Function_Name(parameters)
Relationship
It will be overloaded by the compiler

only 3 ,4
derived data types

Only 5
hardware objects
procedural language
economics
windows

customized array

Int

Void
Double

1
every object of the class is created.
protected
0
Iterators
per = total/(float)m

Compile time

4
Base1's constructor called
Base2's constructor called
Derived's constructor called
56

79
Base Function
11

GeeksforGeeks - A computer science portal for geeks


18

An error occured

An error occurred

stdio.h
Programs
Type safety
Variables store program data while code runs
Variable values can change while a program runs
The size of the memory used by its data type
double
bool lives;
int
bool
String
2
array type
int
alert
integer
enumeration

f is a function taking an argument of type int and retruning a floating point number
double
Array subscripting
postfix
conditional

35
It converts virtual base class to derived class

6
749736

1000

56
1
&
1
if expression
curly braces
yes
cases can't have conditions
cases must be capitalized
1
for
for
for {i=0,i<10,i++}
for
for (i=0; i<5; i++)
yes
for
do {//code}while (condition);

hi
hi
hi
bye

It won't output anything.

3
3
4
5

1
2
3

-2

105
42

0 1 2 3
1197

2 3 4 5

52
For loop
Jump statement
While loop
Break statement

Syntax error

Variable
Digital computing
Preprocessors
break
do-while

To continue to the next line of code


%
To continue to the next line of code
stdlib.h
stdlib.h
read a character from STDIN
Case in switch statement
Unstructured spaghetti code

14

Compilation error
123
1
comments are parts of the source code disregarded by the compiler
single line

hello world
/* …. */
distinguishes between comments and code
It will not return value to its caller
prototype
after int main()
double
int
int
double

subtract (x)

global variable
yes

1
static
call by value

2 5 10

10
6

100
11
It will not return value to its caller
Larger instances of different problems
Factorial of a number
Switch Case
Best case

The code will be executed successfully and no output will be generated


10

return

9
Recursion is always better than iteration
auto
The time during which identifier exists in memory
2
auto
A2
const
procedural
Functions
Virtual Functions
No
<string>
<string>
The second input overwrites the first one
The program worked as expected without any errors during its execution
 default
long int
template< typename T> return_type Function_Name(parameters
Object Association
Its virtual nature will be lost

only 1,3,5
User defined data types

Only 1 and 4
graphic objects
Object oriented language
transport
matlab software

stack

MyMethod

ShowMenu
Value

False

last object of the class is created.


protected
1
Punctuators
per = total/float(m)

Run time

3
Base1's constructor called
55

80
None
12

A computer science portal for geeks


17

54

cstdio
Library
Exception
Variables control memory space
Variables make it possible to process almost any kind of data
The source of the data being stored
int
integer intScore;
double
int
bool
4
character type
short
backslash
boolean
classes

f is a function taking an argument of type float and returning a integer


void
Function call
unary
relational

20
it converts virtual base object to derived objeccts

5
736749

11

65
66
 &&
0
if { expression
scanf
no
cases must be capitalized
cases must have ; not :
0
have
do
for (i=0; i<10; i++);
do
for (i=5; i<=10; i++)
no
do
do {//code}while (condition)

hi
hi

hi

None

7
1
2
3

0
1
2
3

104
54

2 3 4 5
1 0 9 7

2314

55
Foreach loop
Goto statement
Goto statement
Continue statement

Fatal error

Constant
Personal computing
Reserved words
return
if-else
To stop the current iteration and begin the next iteration
from the beginning
+
To stop the current iteration and begin the next iteration
from the beginning
malloc.h
stdio.h
read a character from a file
Initialization in for loop
Infinite loop

Compilation error

123
13
2
comments are executed by compiler to find the meaning of the comment
multi line

hello
/$ …. $/
r distinguishes between comments and outer data
It will return value to its caller
declare
before int main()
int x
double
double
int & double

subtract (y)

local variable
no

2
const
call by reference

245

20
24

compile time error


12
It will return value to its caller
Larger instances of the same problem
Nth fibonacci number
Loop
Worst case

The code will be executed successfully and random output will be genera
1

printf(“%d “, n)

10
Recursion uses more memory compared to iteration
register
Which function is to use
3
register
A3
#define
bottom-up
Objects
Templates

<sstring>
<sstring>
The second input attempt fails since the variable already g
not to end the program yet.
 readable
short int
both a and b
Containership
both a and b

2,4,5
built-in data types

Only 1,2 and 5


control system objects
C++
probability
paint

binary tree

String
1

first object of the class is created.


public
Garbage value
Manipulators
per = (float)total/m

Both a and b

2
Base2's constructor called
54

81
Base Function and Base
13

GeeksforGeeks
16

15

85

iostream
Streams
Both Type safety & Exception
Variables are individual values in a database table
All variables use the same amount of memory
The physical address location in memory
String
char Broiled;
bool
decimal
int
2 or 4
boolean type
void
tab
character
both enumeration and classes

f is a function of type float


int
Addition and subtraction
shif
casting operator

25
it will convert the operator based on precedence

4
367497

1010

67
-1
|
Unevaluatable
 if ( expression )
break

cases must have ; not :


nothing

do
while
for (i=0; i<10; i++)
while
for (i=5; i=10; i++)

while
do {//code}while (condition):

hi
bye
hi

it won't input

6
3
4
5
6

0
1
2

103
24

2 3 4
1 1 9 8

2215

53
Switch Statement
Spaghetti Statement
For loop
Switch statement

Termination error

Operator
Distributed computing
Punctuation marks
exit
for

To handle run time error


::
To handle run time error
calloc.h
stdout.h
read all file
Continuation condition in for loop
Break Statement

124

12
132
3
comments are executable
single line and multi line

compile time error


//
both a and b
Maybe or maynot be return value to its caller
initialize
a prototype isn't necessary
numbers
char
char
int

subtract (x,y)

extended variable
3
absolute
call by pointer

2 6 14

15
segmentation fault

144
13
Maybe or maynot be return any value to its caller
Smaller instances of the same problem
Length of a string
If-else
Base case

The code will show a compile time error


10 9 8 … 1 0

if(n == 0)

11
Recursion uses less memory compared to iteration
extern
Where to store program
4
static
A4 A
All of these 4
all of these. 3
Data types 3
None of these 3
1
<sstream> 1
<sstream> 4
You can not use same variable for two getline statements 2
None of above 2
volatile 3
float 3
None of these 3
None of these 3
Compiler will generate “Prototype mismatch error” 3

Only 2,3 4
All of these 2

Only 2 and 5 4
circuit designing objects 2
JAVA 1
country 4
joystick 1

decimal tree

3
Double 4

Category 4
2 1

1
No need to initialize static variable. 3
static 2
Compiler dependent 1
Allocators 3
None of these 2

None of these 2

1 1
Derived's constructor called 1
53 1

82 2
Based 1
10 4

None

1
15 1

42 1

74 1

none of the mentioned 2


None of the mentioned 3
None of the mentioned 1
Variables enable programmers to work with different input devices 1
Variables must be stored in a database or file if they are to be retained w 3
A name to reference the data type 4
char 4
double DeCtuRn; 2
String 2
String 4
double 3
based on the number of bits in the system 4
integer type 1
float 3
form feed 1
all of the mentioned 2
int 3

none of the mentioned 2


bool 1
Type cast 4
equality 1
none of the mentioned 1

30 2
none of the mentioned 1

7 1
none of the mentioned 1

1001 3

none of the mentioned 1


All of the above 4
|& 2
1
expression if 3
3
2
1
3
2
while 2
2
3
2
3
1
all 4
1

hi
hi
bye
hi
1

all 1

4 3
1

5 1

102 1
44 1

45 6 1
1 0 1 6 1

2323 1

54 1
None of them 3
None of them 1
Foreach loop 2
All of them 4

Both B and C
2
None of them 2
Client/server computing 2
Operators 2
Both break and return 2
while 2

None of above
2
- 3

None of above
2
None of above 1
stdoutput.h 2
read file random 2
All of them 1
None of them 1

134 1

13 2
Compilation error 4
4 2
none of the mentioned 1
none of the mentioned 3

none of the mentioned 3


none of the mentioned 1
none of the mentioned 1
None of the mentioned 1
1
2
3
2
1
1

3
2
1
4 3
none of the mentioned 2
none of the mentioned 1

none of the mentioned 3

none of the mentioned 2


compile time error 3

110 4
compile time error 3
None of the mentioned 1
Smaller instances of different problems 3
All of the mentioned 4
None of the mentioned 2
There is no such condition 3

The code will run for some time and stop when the stack overflows 4
10 9 8 … 1 4

my_recursive_function(n-1) 3

12 3
Iteration is always better and simpler than recursion 2
mat 4
None of them 1
5 4
volatile 4

You might also like