C++ Cert Exam

Ace your homework & exams now with Quizwiz!

How many vector container properties are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three container properties in c++. They are sequence, Dynamic array and allocator-aware.

How many real types are there in complex numbers? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three real types in complex numbers. They are float complex, double complex, long double complex.

Evaluate the following (false && true) || false || true a) 0 b) 1 c) false d) none of the mentioned

Answer:b Explanation: None.

What is the output of this program? #include <iostream> using namespace std; #define PR(id) cout << "The value of " #id " is "<<id int main() { int i = 10; PR(i); return 0; } a) 10 b) 15 c) 20 d) none of the mentioned

Answer:a Explanation:In this program, we are just printing the declared values. Output: 10

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

Answer:a Explanation:None.

How many types of loops are there? a) 4 b) 2 c) 3 d) 1

Answer:a Explanation:There are four types of loop. They are while, do while, nested, for loop.

which keyword is used to define the macros in c++? a) macro b) define c) #define d) none of the mentioned

Answer:c Explanation:None.

How many types of returning values are present in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:The three types of returning values are return by value, return by reference and return by address.

Which datatype is used to represent the absence of parameters? a) int b) short c) void d) float

C) void void will not return anything.

#include <iostream> using namespace std; int main() { string s1 = "1"; string s2 = "12"; cout << s1.compare(s2); return 0; } Select correct answer (single choice) It prints -1 Compilation fails It prints 0 It prints 1

It prints -1

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int main() { string s1 = "top"; string s2; s2.append(s1).append("down"); cout << s2; return( 0 ); } Select correct answer (single choice) It prints: downtop It prints: topdown It prints: top It prints: down

topdown

Which statement will you add in the following program to make it correct? #include <string> int main() { std::string s = "Here I am!"; std::cout << s; return 0; } Select correct answer (single choice) #include <string> #include <stdexcept> #include <iostream> #include <cmath>

#include <iostream>

The destination statement for the goto label is identified by what label? a) $ b) @ c) * d) :

Answer:d Explanation:None.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main (int argc, const char *argv[]) { int a = 1, b = 1, c = 1, i = 1; i = b < a < c; cout << i; return 0; } Select correct answer (single choice) It prints: 2 It prints: 1 It prints: 4 Compilation fails

1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class cmplx{ double re,im; public: cmplx() : re(0),im(0) {} cmplx(double x) { re = im = x; } cmplx(double x,double y) { re = x; im = y; } void out() { cout << "(" << re << "," << im << ")"; } }; int main(){ cmplx c(1,2), cc(c); cc.out(); return 0; } Select correct answer (single choice) It prints: (2,2) It prints: (1,1) It prints: (1,2) It prints: (2,1)

(1,2)

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class cmplx{ double re, im; public: cmplx() : re(1),im(1) {} cmplx(double r, double i) : re(r),im(i) {} cmplx operator+(cmplx &); void out() { cout << "(" << re << "," << im << ")"; } }; cmplx cmplx::operator+ (cmplx &a){ cmplx c(this->re + a.re, this->im + a.im); return c; } int main(){ cmplx x(1,2),y,z; z = x + y; z.out(); return 0; } Select correct answer (single choice) It prints: (3,3) It prints: (2,3) It prints: (3,2) It prints: (2,2)

(2,3)

#include <iostream> using namespace std; int main() { int t[3] = { 3, 2, 1 }, *ptr = t + 1; (*(ptr + 1))++; *ptr++; cout << t[1] << t[2]; return 0; } Select correct answer (single choice) 32 22 33 23

22

What happens when you attempt to compile and run the following code? #include <iostream> #include <cstdarg> using namespace std; int calculate(int &val, int arg) { val *= arg; return arg; } int main() { int i = 1; int j = calculate(i,2); cout << i << j; return 0; } Select correct answer (single choice) It prints: 11 It prints: 22 It prints: 12 It prints: 21

22

#include <iostream> using namespace std; int *make(int v) { int *p = new int; *p = v + 1; return p; } int *play(int &v) { cout << ++v; return &v; } void remove(int *v) { delete v; } int main() { remove(play(*make(3))); return 0; } Select correct answer (single choice) 3 5 2 4

5

How many times will the program print "HI!"? #include <iostream> using namespace std; int X = 5; int main() { cout << "HI!"; if(X-- > 0) main(); return 0; } Select correct answer (single choice) 2 5 1 6

6

Which value is pointed out first in heap? a) Lowest value b) Highest value c) First value d) None of the mentioned

:b Explanation:The element with the highest value is always pointed by first.

How to store the large objects in c++ if it extents its allocated memory? a) memory heap b) stack c) queue d) None of the mentioned

A

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> using namespace std; class myClass : public exception { virtual const char* what() const throw() { return "My exception."; } } obj; int main () { try{ throw obj; } catch (exception& e){ cout << e.what() << endl; } return 0; } A. It prints: My exception. B. It prints: 0 C. It prints: 1 D. Compilation error

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; struct { int x; char c; union { float f; int i; }; } s; int main (int argc, const char * argv[]) { s.x=10; s.i=0; cout << s.i << " " << s.x; } A. It prints: 0 10 B. It prints: 11 C. Compilation error D. None of these

A

Which is dependant on template parameter? a) base class b) abstract class c) method d) None of the mentioned

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Alpha { public: char out(){ return 'A'; } }; class Beta : public Alpha { public: virtual char out(){ return 'B'; } }; class Gamma : public Beta { public: char out(){ return 'G'; } }; int main() { Alpha *a = new Alpha(); Alpha *b = new Beta(); Alpha *c = new Gamma(); cout << (a->out()) << (b->out()) << (c->out()); return 0; } Select correct answer (single choice) It prints: AAA It prints: GGG It prints: ABG It prints: BBB

AAA

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; if (i++==1) { cout << i; } else { cout << i-1; } return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. It prints: 2

Answer D

#include <iostream> using namespace std; int main() { int *t; t = new int[2]; for (int i=0; i<2; i++) { t[i]=0; } cout << t[1]; } A. It prints: 0 B. It prints: 1 C. It prints: 2 D. It prints: 3

Answer: A

Which code, inserted at line 12, generates the output "5b"? #include <iostream> using namespace std; namespace myNamespace1 { int var = 5; } namespace myNamespace2 { char var = 'b'; } int main () { //insert code here return 0; } A. cout << myNamespace1::var << var; B. cout << var << var; C. cout << myNamespace1::var << myNamespace2::var; D. None of these

Answer: C

Which symbol is used to declare the preprocessor directives? a) # b) $ c) * d) ^

Answer:# Explanation:None.

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { protected: int y; public: int x; int z; A() { x=1; y=2; z=3; } A(int a, int b) : x(a), y(b) { z = x * y;} void Print() { cout << z; } }; int main () { A a(2,5); a.Print(); return 0; } A. It prints: 10 B. It prints: 2 C. It prints: 6 D. It prints: 5

Answer:A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"H" , "t" }; string s; for (int i=0; i<2; i++) { s = s1[i]; s.insert(1,"o"); cout << s; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 198C++ Institute CPA Exam } return( 0 ); } A. It prints: Hoto B. It prints: Ho C. It prints: to D. It prints: Ht

Answer:A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: First() { cout << "Constructor";} void Print(){ cout<<"from First";} }; int main() { First FirstObject; FirstObject.Print(); } A. It prints: Constructorfrom First B. It prints: Constructor C. It prints: from First D. None of these

Answer:A

Which definitions are correct? A. int age; B. int double; C. char c; D. int char;

Answer:A,C

How many times will "HELLO" be printed? #include <iostream> using namespace std; int main() { for(int i=?1; i<=10; i++) { if(i < 5) continue; else break; cout<<"HELLO"; } return 0; } A. 1 B. 2 C. 0 D. 20

Answer:C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; A() { x=1; y=2; z=3; } }; class B : public A { string z; public: void set() { y = 4; z = "John"; } void Print() { cout << y << A::z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 4John B. It prints: 2John C. It prints: 23 D. It prints: 43

Answer:D

What is the output of this program? #include <iostream> using namespace std; enum colour { green, red, blue, white, yellow, pink }; int main() { cout << green<< red<< blue<< white<< yellow<< pink; return 0; } a) 012345 b) 123456 c) compile time error d) runtime error

Answer:a EXplanation:The enumerator values start from zero if it is unassigned. Output: $ g++ enum3.cpp $ a.out 012345

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

Answer:a Explanation: Because the dynamic_cast operator is used to convert from base class to derived class.

What is the output of this program? #include <iostream> using namespace std; int main () { int n; for (n = 5; n > 0; n--) { cout << n; if (n == 3) break; } return 0; } a) 543 b) 54 c) 5432 d) 53

Answer:a Explanation: In this program, We are printing the numbers in reverse order but by using break statement we stopped printing on 3. Output: 543

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 5, c; void *p = &a; double b = 3.14; p = &b; c = a + b; cout << c << '\n' << p; return 0; } a) 8, memory address b) 8.14 c) memory address d) none of the mentioned

Answer:a Explanation: In this program, we are just adding the two values and printing it. Output: 8 0xbfef0378

Identify the type of the variables. typedef char* CHAR; CHAR p,q; a) char* b) char c) CHAR d) unknown

Answer:a Explanation: The statement makes CHAR a synonym for char*.

What is the output of this program? #include <iostream> using namespace std; namespace extra { int i; } void i() { using namespace extra; int i; i = 9; cout << i; } int main() { enum letter { i, j}; class i { letter j; }; ::i(); return 0; } a) 9 b) 10 c) compile time error d) none of the mentioned

Answer:a Explanation:A scope resolution operator without a scope qualifier refers to the global namespace.

What is meant by template parameter? a) It can be used to pass a type as argument b) It can be used to evaluate a type. c) It can of no return type d) None of the mentioned

Answer:a Explanation:A template parameter is a special kind of parameter that can be used to pass a type as argument.

Which of the following accesses a variable in structure *b? a) b->var; b) b.var; c) b-var; d) b>var;

Answer:a Explanation:Because in a structure pointer, the data element is declared as above only.

What will happen when defining the enumerated type? a) it will not allocate memory b) it will allocate memory c) it will not allocate memory to its variables d) none of the mentioned

Answer:a Explanation:Enumerator will allocate the memory when its variables are defined.

Which of the following type does the container should define? a) Iterator type b) Vector type c) Storage type d) None of the mentioned

Answer:a Explanation:Every container must define an iterator type. Iterators allow algorithms to iterate over the container's contents.

What is the output of this program? #include <iostream> using namespace std; struct a{ int count; }; struct b{ int* value; }; struct c : public a, public b{ }; int main(){ c* p = new c; p->value = 0; cout << "Inherited"; return 0; } a) Inherited b) Error c) Runtime error d) None of the mentioned

Answer:a Explanation:In this program, We apply the multiple inheritance to structure. Output: $ g++ mul2.cpp $ a.out Inherited

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (5); int* p = myvector.data(); *p = 10; ++p; *p = 20; p[2] = 100; for (unsigned i = 0; i < myvector.size(); ++i) cout << ' ' << myvector[i]; return 0; } a) 10 20 0 100 0 b) 10 20 0 100 c) 10 20 0 d) 10 20

Answer:a Explanation:In this program, We are allocating the values to the vector and unallocated values are left as zero. Output: $ g++ vect4.cpp $ a.out 10 20 0 100 0

What is the output of this program? #include<iostream> using namespace std; class X { int m; public: X() : m(10) { } X(int mm): m(mm) { } int getm() { return m; } }; class Y : public X { int n; public: Y(int nn) : n(nn) {} int getn() { return n; } }; int main() { Y yobj( 100 ); cout << yobj.getm() << " " << yobj.getn() << endl; } a) 10 100 b) 100 10 c) 10 10 d) 100 100

Answer:a Explanation:In this program, We are passing the value and getting the result by derived class. Output: $ g++ der5.cpp $ a.out 10 100

What is the output of this program? #include <iostream> using namespace std; template <class T> inline T square(T x) { T result; result = x * x; return result; }; template <> string square<string>(string ss) { return (ss+ss); }; int main() { int i = 4, ii; string ww("A"); ii = square<int>(i); cout << i << ii; cout << square<string>(ww) << endl; } a) 416AA b) 164AA c) AA416 d) none of the mentioned

Answer:a Explanation:In this program, We are using two template to calculate the square and to find the addition. Output: $ g++ tem.cpp $ a.out 416AA

What is a template? a) A template is a formula for creating a generic class b) A template is used to manipulate the class c) A template is used for creating the attributes d) none of the mentioned

Answer:a Explanation:None

Identify the correct statement. a) c++ does not have built-in interfaces b) c++ does have built-in interfaces c) c++ have no cocept of interfaces d) none of the mentioned

Answer:a Explanation:None.

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

Answer:a Explanation:None.

What is meant by containership? a) class contains objects of other class types as its members b) class contains objects of other class types as its objects c) both a & b d) none of the mentioned

Answer:a Explanation:None.

What is meant by type_info? a) Used to hold the type information returned by the typeid operator b) Used to hold the type information returned by the dynamic_cast c) Used to hold the type information returned by the static cast d) None of the mentioned

Answer:a Explanation:None.

What is the default calling convention for a compiler in c++? a) __cdecl b) __stdcall c) __pascal d) __fastcall

Answer:a Explanation:None.

What is the general syntax for accessing the namespace variable? a) namespaceid::operator b) namespace,operator c) namespace#operator d) none of the mentioned

Answer:a Explanation:None.

What is the use of vector arithmetic in c++? a) Computer graphics b) Computer booting c) Both a & b d) None of the mentioned

Answer:a Explanation:None.

What is the validity of template parameters? a) inside that block only b) inside the class c) whole program d) any of the mentioned

Answer:a Explanation:None.

How the member functions in the container can be accessed? a) Iterator b) Indirect c) Both a & b d) None of the mentioned

Answer:a Explanation:The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators which reference objects with similar properties to pointers.

What is the output of this program? #include <iostream> using namespace std; enum cat { temp = 7 }; int main() { int age = 14; age /= temp; cout << "If you were cat, you would be " << age << endl; return 0; } a) If you were cat, you would be 5 b) If you were cat, you would be 2 c) If you were cat, you would be 7 d) none of the mentioned

Answer:b Explanation: The age will be divided by using compound assignment operator and so it will return the age of the cat according to your age. If you were cat, you would be 2

What is the output of this program? #include <iostream> using namespace std; int mult (int x, int y) { int result; result = 0; while (y != 0) { result = result + x; y = y - 1; } return(result); } int main () { int x = 5, y = 5; cout << mult(x, y) ; return(0); } a) 20 b) 25 c) 30 d) 35

Answer:b Explanation: We are multiplying these values by adding every values. Output: $ g++ ret.cpp $ a.out 25

To where does the program control transfers when exception is arised? a) catch b) handlers c) throw d) none of the mentioned

Answer:b Explanation: When a exception is arised mean, the exception is caught by handlers and then it decides the type of exception.

Choose the incorrect option a) void is used when the function does not return a value. b) void is also used when the value of a pointer is null. c) void is used as the base type for pointers to objects of unknown type. d) void is a special fundamental type.

Answer:b Explanation: void fundamental type is used in the cases of a and c.

What is the output of this program? #include <iostream> using namespace std; namespace first { int var = 5; } namespace second { double var = 3.1416; } int main () { int a; a = first::var + second::var; cout << a; return 0; } a) 8.31416 b) 8 c) 9 d) compile time error

Answer:b Explanation:As we are getting two variables from namespace variable and we are adding that. Output: 8

What type of reference should be used in vector arithmetic? a) dynamic b) const c) Both a & b d) None of the mentioned

Answer:b Explanation:As we are using the vector and it will give accurate result if we use const reference.

What is the new value of x? #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; } a) 10 b) 20 c) 15 d) none of the mentioned

Answer:b Explanation:As we passed by reference, the value is changed and it is returned as 20. Output: 20

Which is used to keep the call by reference value as intact? a) static b) const c) absolute d) none of the mentioned

Answer:b Explanation:Because const will not change the value of the variables during the execution.

Pick out the correct statement about string template. a) It is used to replace a string. b) It is used to replace a string with another string at runtime. c) It is used to delete a string. d) none of the mentioned

Answer:b Explanation:Every string template is used to replace the string with another string at runtime.

In which type does the enumerators are stored by the compiler? a) string b) integer c) float d) none of the mentioned

Answer:b Explanation:None.

To which type of class, We can apply RTTI? a) Encapsulation b) Polymorphic c) Derived d) None of the mentioned

Answer:b Explanation:RTTI is available only for classes which are polymorphic, which means they have at least one virtual method.

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

Answer:b Explanation:The main aim of the namespace is to understand the logical units of the program and to make the program so robust.

How many minimum number of functions are need to be presented in c++? a) 0 b) 1 c) 2 d) 3

Answer:b Explanation:The main function is the mandatory part, it is needed for the execution of the program to start.

What is meant by permutation in c++? a) To find all the values in the range b) To find all the combination of the range c) Both a & b d) None of the mentioned

Answer:b Explanation:The permutation is used to find all the combination of numbers in the range.

Which function is used to optimize the space in vector? a) at b) bool c) operator d) None of the mentioned

Answer:b Explanation:This is a specialized version of vector, which is used for elements of type bool and optimizes for space.

What do vectors represent? a) Static arrays b) Dynamic arrays c) Stack d)Queue

Answer:b Explanation:Vectors are sequence containers representing arrays that can change in size.

What is the output of this program? #include <iostream> using namespace std; void Sum(int a, int b, int & c) { a = b + c; b = a + c; c = a + b; } int main() { int x = 2, y =3; Sum(x, y, y); cout << x << " " << y; return 0; } a) 2 3 b) 6 9 c) 2 15 d) compile time error

Answer:c Explanation:We have passed three values and it will manipulate according to the given condition and yield the result as 2 15 Output: 2 15

The constants are also called as a) const b) preprocessor c) literals d) none of the mentioned

Answer:c EXplantion: None.

What is the output of this program? #include <iostream> using namespace std; int main() { enum channel {star, sony, zee}; enum symbol {hash, star}; int i = 0; for (i = star; i <= zee; i++) { printf("%d ", i); } return 0; } a) 012 b) 123 c) compile time error d) runtime error

Answer:c Explanation: enumartion variable 'star' appears two times in main() which causes the error. An enumaration constant must be unique within the scope.

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

Answer:c Explanation:As a rule, the default argument must be followed by default arguments only.

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

Answer:c Explanation:As it is used to execute a block of code, So we will not allocate or deallocate memory.

What is the output of this program? #include <iostream> using namespace std; void Funct(); int main() { try { Funct(); } catch(double) { cerr << "caught a double type..." << endl; } return 0; } void Funct() { throw 3; } a) caught a double type b) compile time error c) abnormal program termination d) none of the mentioned

Answer:c Explanation:As we are throwing integer to double it will raise as abnormal program after termination throw statement. Output: $ g++ excep4.cpp $ a.out terminate called after throwing an instance of 'int' Aborted

Why we use :: template-template parameter? a) binding b) rebinding c) both a & b d) none of these

Answer:c Explanation:It is used to adapt a policy into binary ones.

What is the output of this program? #include <iostream> using namespace std; #define MAX 10 int main() { int num; num = ++MAX; cout << num; return 0; } a) 11 b) 10 c) compile time error d) none of the mentioned

Answer:c Explanation:Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can't increment the value.

How many kinds of parameters are there in C++? a) 1 b) 2 c) 3 d) None of the mentioned

Answer:c Explanation:There are three kinds of parameters are there in C++. They are type, non-type, template.

How many types of output stream classes are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three output stream classes in c++. They are ostream, ofstream and ostrstream.

How many sets of requirements are need in designing a container? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three sets of requirements. They are container interface requirements, Allocator interface requirements and iterator requirements.

What is the output of this program? #include <iostream> using namespace std; #define SquareOf(x) x * x int main() { int x; cout << SquareOf(x + 4); return 0; } a) 16 b) 64 c) compile time error d) none of the mentioned

Answer:d Explanation:In this program, as we haven't initialized the variable x, we will get a output of ending digit of 4. Output: 75386824

What is the output of the following program? #include <iostream> using namespace std; int operate (int a, int b) { return (a * b); } float operate (float a, float b) { return (a / b); } int main() { int x = 5, y = 2; float n = 5.0, m = 2.0; cout << operate(x, y) <<"\t"; cout << operate (n, m); return 0; } a) 10.0 5.0 b) 5.0 2.5 c) 10.0 5 d) 10 2.5

Answer:d Explanation:In this program, we are divide and multiply the values. Output: 10 2.5

What is the output of this program? #include <iostream> using namespace std; void square (int *x) { *x = (*x + 1) * (*x); } int main ( ) { int num = 10; square(&num); cout << num; return 0; } a) 100 b) compile time error c) 144 d) 110

Answer:d Explanation:We have increased the x value in operand as x+1, so it will return as 110. Output: 110

What is the output of this program? #include <iostream> using namespace std; int main() { char* buff; try { buff = new char[1024]; if (buff == 0) throw "Memory allocation failure!"; else cout << sizeof(buff) << "Byte successfully allocated!"<<endl; } catch(char *strg) { cout<<"Exception raised: "<<strg<<endl; } return 0; } a) 4 Bytes allocated successfully b) 8 Bytes allocated successfully c) Memory allocation failure d) depends on the size of data type

Answer:d Explanation:As we are allocating the memory to the variables and if there is not suffcient size means, it will throw an exception. Output: $ g++ excep3.cpp $ a.out 4 Bytes allocated successfully

____ have the return type void? a) all functions b) constructors c) destructors d) none of the mentioned

Answer:d Explanation:Constructor creats an Object and Destructor destroys the object. They are not supposed to return anything, not even void.

A void pointer cannot point to which of these? a) methods in c++ b) class member in c++ c) all of the mentioned d) none of the mentioned

Answer:d Explanation:None.

Choose the correct option. extern int i; int i; a) both 1 and 2 declare i b) 1 declares the variable i and 2 defines i c) 1 declares and defines i, 2 declares i d) 1 declares i,2 declares and defines i

Answer:d Explanation:The keyword extern is not a definition and is not allocated storage until it is initialized.

#include <iostream> using namespace std; int main(){ int i = 1; if (i==1) { cout << i; } else { cout << i-1; } return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. It prints: 2

B

#include <iostream> using namespace std; class complex{ double re; double im; public: complex() : re(0),im(0) {} complex(double x) { re=x,im=x;}; complex(double x,double y) { re=x,im=y;} void print() { cout << re << " " << im;} }; int main(){ complex c1(1,2); c1.print(); return 0; } A. It prints: 1 0 B. It prints: 1 1 C. It prints: 1 2 D. Compilation error

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int x=5; static int y=0; void myFunction(int a) { y=++a; } int main (int argc, const char * argv[]) { int i=0; myFunction(i); cout<<y<<" "<<x; } A. It prints: 0 5 B. It prints: 5 1 C. It prints: 1 5 D. It prints: 5 0

C

Which of the structures is incorrect? 1: struct s1{ int x; long int li; }; 2: struct s2{ float f; struct s2 *s; }; 3: struct s3{ float f; struct s3 s; }; A. 1 B. 2 C. 3 D. 2, 3

C

What is the output of the program if character 4 is supplied as input? #include <iostream> using namespace std; int main () { int c; cin >> c; try{ switch (c){ case 1: throw 20; case 2: throw 5.2f; case 3: throw 'a'; default: cout<<"No exception"; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (float e) { cout << "float exception. Exception Nr. " << e; } catch (...) { cout << "An exception occurred."; } return 0; } A. It prints: float exception. Exception Nr. B. It prints: int exception. Exception Nr. C. It prints: An exception occurred D. It prints: No exception

D

What will be the output of the this program? #include <stdio.h> 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; }

Explanation:We are adding all the elements in the array and printing it. Total elements in the array is 7, but our for loop will go beyond 7 and add a garbage value.

What is the output of this program? #include <iostream> using namespace std; int main() { char str[] = "Hello\0World\0"; cout << str; return 0; } Select correct answer (single choice) Hello Hello\0World HelloWorld Compilation fails

Hello

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { char i = '1'; switch(i) { case '1': cout<<"Hello "; case '2': cout<<"world "; break; case '3': cout<<"!"; } return 0; } Select correct answer (single choice) It prints nothing It prints "Hello world " It prints "Hello world !" It prints "Hello "

It prints "Hello world "

#include <iostream> #include <exception> using namespace std; int main() { try { throw 2/4; } catch(int i) { cout << i; } return 0; } Select correct answer (single choice) It prints 0.5 Execution fails Compilation fails It prints 0

It prints 0

#include <iostream> using namespace std; class A { public: int cnt; void put(int v); }; void A::put(int v) { cout << ++cnt; } int main() { A a[2]; a[0].cnt = 0; a[1].cnt = 1; a[a[0].cnt].put(a[1].cnt); return 0; } Select correct answer (single choice) It prints 0 It prints 2 Compilation fails It prints 1

It prints 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { friend class B; private: int field; public: int set(int x) { return field = ++x; } int get() { return ++field; } }; class B { public: void kill(A &a) { a.field = 0; } }; int main() { A a; B b; a.set(1); b.kill(a); cout << a.get(); return 0; } Select correct answer (single choice) It prints 1 Compilation fails It prints 0 It prints 2

It prints 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: int v; void put(int x) { v = x; } int get(void) { return v; } }; class Y : public X { public: Y() { put(0); } void write(int x) { put(x + 1); } int read(void) { return get() - 1; } }; int main() { Y *y = new Y(); y->write(1); cout << y->read(); delete y; return 0; } Select correct answer (single choice) It prints 0 It prints 1 It prints -1 Compilation fails

It prints 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int doit(int x) { return x << 1; } int main(){ int i; i = doit(1) || doit(0); cout << i; return 0; } Select correct answer (single choice) It prints: 0 It prints: false It prints: 1 It prints: true

It prints 1

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> #include <stdexcept> using namespace std; class X : public domain_error { public: X() : domain_error("0") {}; }; void z() throw(X) { X x; throw x; cout << 1; } int main(void) { X x; try { z(); } catch(X &i) { cout << 1; } catch(domain_error &i) { cout << 0; } return 0; } Select correct answer (single choice) It prints 0 Execution fails It prints 1 Compilation fails

It prints 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: X(void) throw(int) { cout << 1; } ~X(void) throw(int) { cout << 2; } void exec() { throw 0; } }; void exec(X &x) { x.exec() ; } int main(void) { X x; try { exec(x); } catch(int &i) { cout << i; } return 0; } Select correct answer (single choice) Execution fails Compilation fails It prints 120 It prints 102

It prints 102

#include <iostream> using namespace std; class A { public: float v; A() { v = 1.0; } A(A &a) { A::v = a.v; cout << "1"; } ~A() { cout << "0"; } float set(float v) { A::v = v; return v; } float get(float v) { return A::v; } }; int main() { A a,*b = new A(a),*c = new A(*b); c->get(b->get(a.set(1.0))); delete b; delete c; return 0; } Select correct answer (single choice) Compilation fails It prints 1100 It prints 11000 It prints 110

It prints 11000

#include <iostream> using namespace std; class A { public: float v; float set(float v) { A::v += 1.0; return v; } float set(void) { A::v = v + 1.0; return 0.0; } float get(float v) { v += A::v; return v; } }; int main() { A a; a.v=0; cout << a.get(a.set(a.set(a.set()))); return 0; } Select correct answer (single choice) It prints 1 It prints 2 Compilation fails It prints 3

It prints 3

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class One { public: float f; One(float f) { this -> f = f; } }; class Two { public: float f; Two (One o) { this -> f = o.f; } void foo() { cout << (int)f; } }; int main() { One o1(3.14); Two o2 = o1; o2.foo(); } Select correct answer (single choice) It prints: 3 Compilation fails It prints: 3.14 It prints: 0

It prints 3

#include <iostream> using namespace std; class A { public: A() { v = 2.5; } A(float v) { A::v = v + 1.0; } float v; float set(float v) { A::v += 1.0; return v; } float get(float v) { v += A::v; return v; } }; int main() { A a,b(1.0); cout << a.get(b.set(1.5)); return 0; } Select correct answer (single choice) It prints 1 It prints 2 Compilation fails It prints 4 (correct)

It prints 4

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: virtual void shout() { cout << "X"; } }; class Y : public X { public: void shout() { cout << "Y"; } }; class Z : public Y { public: void shout() { cout << "Z"; } }; int main() { Y *y = new Z(); dynamic_cast<X *>(y) -> shout(); return 0; } Select correct answer (single choice) It prints X It prints Z It prints Y Compilation fails

It prints Z

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Zero { public: void out(){ cout << 0;} }; class One : public Zero { public: void out(){ cout << 1;} }; class Two : public Zero { public: void out(){ cout << 2;} }; int main() { Zero *obj; One obj1; obj = &obj1; obj->out(); Two obj2; obj = &obj2; obj->out(); return 0; } Select correct answer (single choice) It prints: 12 It prints: 02 It prints: 00 It prints: 01

It prints: 00

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int doit(int a, float b) { return a / b; } int main() { float x = doit(1.5f, 2l); cout << x << ":" << doit(1, 1.f); return 0; } Select correct answer (single choice) It prints: 0:0 It prints: 1:1 It prints: 1:0 It prints: 0:1

It prints: 0:1

What is the output of this program? #include <iostream> #include <string> using namespace std; class Uno { int val; public: Uno(int x) { val = x; } int out() { return val; } void operator++(int var) { val += val; } }; ostream &operator<<(ostream &o, Uno u) { return o << u.out(); } int main() { Uno i(2); i++; cout << i; return 0; } Select correct answer (single choice) 4 3 1 2

It prints: 4

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int f(int a) { return a + a; } int main() { int i = 0; for(int a = 0; a < 2; a++) i = f(i + 1); cout << i; return 0; } Select correct answer (single choice) It prints: 2 It prints: 6 It prints: 9 It prints: 3

It prints: 6

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 8; do { i--; cout << i--; } while(i); return 0; } Select correct answer (single choice) It prints: 6543210 It prints: 76543210 It prints: 6420 It prints: 7531

It prints: 7531

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; float doit(int a, int b) { return a * b; } float doit(float a, float b) { return a + b; } int main() { cout << doit(doit(1,2),doit(3.f,4.f)); return 0; } Select correct answer (single choice) It prints: 14 It prints: 9 Compilation error It prints: 21

It prints: 9

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int cnt = 10; do { cnt--; if (cnt % 3 == 2) break; cout << cnt; } while(cnt); return 0; } Select correct answer (single choice) It prints: 987654321 It prints: 10987654321 It prints: 109 It prints: 9

It prints: 9

hat happens when you attempt to compile and run the following code? #include <iostream> using namespace std; char max(char x, char y) { if(x > y) return y; else return x; } int main() { char chr = max('a', 'z'); cout << chr; return 0; } Select correct answer (single choice) It prints: z It prints: az It prints: a Compilation error

It prints: a

What happens when you attempt to compile and run the following code? #include <iostream> #include <sstream> #include <string> using namespace std; int main(void) { string s; s = "abcd"; s.append(s); s.resize(s.size() / 2); cout << s; return 0; } Select correct answer (single choice) It prints: abcdabcd It prints an empty string Compilation fails It prints: abcd

It prints: abcd

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; char fun(char *p) { char c = *p; (*p)++; return c; } int main() { char array[3]={'a', 'b', 'c'}; fun(array + 1); cout << fun(array + 1); return 0; } Select correct answer (single choice) Compilation fails It prints: c It prints: b It prints: a

It prints: c

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { char *abc; abc = new char[26]; for(int i = 0; i < 26; i++) abc[i] = 'a' + i; cout << *(abc + 2); return 0; } Select correct answer (single choice) It prints: a It prints: c It prints: b It prints: d

It prints: c

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 2; float f = 1.4; char c = 'a'; bool b = true; c += i + f + b; cout << c; return 0; } Select correct answer (single choice) It prints: d It prints: f It prints: c It prints: e

It prints: c

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> #include <exception> using namespace std; class a { public: virtual string whose() { return "mine"; } }; class b { public: virtual string whose() { return "yours"; } }; int main () { a b; try { throw b; } catch (a& e) { cout << e.whose() << endl; } return 0; } Select correct answer (single choice) It prints: yours It prints: mineyours It prints: mine It prints: yoursmine

It prints: mine

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 2; if (i--==1) cout << i; else cout << i + 1; return 0; } Select correct answer (single choice) It prints: 1 It prints: 2 It prints: i + 1 It prints: 3

It prints:2

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class one { public : void foo() { cout << 1; } }; class two { public : void foo() { cout << 2; } }; int main() { two objects[2]; two *object = objects; for(int i = 0; i < 2; i++) (object++)->foo(); return 0; } Select correct answer (single choice) It prints: 12 It prints: 11 It prints: 22 It prints: 21

It prints:22

6. What is the output of the following program? #include <iostream> using namespace std; int main() { int num = 0x20 + 020 + 20; cout << sizeof(num)<<'\n'; return 0; } a) 2 b) 4 c) Depends on compiler. d) garbage

View Answer Answer:c Explanation:The sum of three numbers are belongs to different number systems, so the result is typecasted into integer. Output: 4

What will be the type of output of vector cross product? a) Scaler b) Vector c) Both a & b d) None of the mentioned

b

#include <iostream> using namespace std; class complex{ double re; double im; public: complex() : re(0),im(0) {} complex(double x) { re=x,im=x;}; complex(double x,double y) { re=x,im=y;} void print() { cout << re << " " << im;} }; int main(){ complex c1; c1 = 3.0; c1.print(); return 0; } A. It prints: 0 0 B. It prints: 1 1 C. It prints: 3 3 D. Compilation error

c

Which code, inserted into the B class, generate the output "ef"? #include <iostream> #include <string> using namespace std; class Alpha { int p; protected: int q; public: int r; Alpha():p(2),q(3),r(4) {} }; class Beta : public Alpha { string s; public: int y; void assign() { y = 4; s = "f"; } void out() { // insert code here } }; int main () { Beta b; b.assign(); b.out(); return 0; } Select correct answer (single choice) cout << char('a' + r) << s; cout << p << r; cout << 'a' + r << s; cout << r << s;

cout << char('a' + r) << s;

Which code, inserted into function main, generates the output "abba"? #include <iostream> #include <string> using namespace std; string fun(string s) { return s.substr(0,1)+s.substr(1,1)+s.substr(1,1)+s.substr(0,1); } int main() { string *s = new string("ab"); //insert code here return 0; } Select correct answers (multiple choice) cout << fun("abba"); cout << fun(*s); cout << fun("ab"); cout << fun(s);

cout << fun(*s);

Which code, inserted into the function main, generates the output "03"? #include <iostream> using namespace std; class Uno { public: void foo(){ cout << "0";} void bar(){ cout << "1";} }; class Due : public Uno { public: void foo(){ cout << "2";} void bar(){ cout << "3";} }; int main() { Due d; // insert code here d.bar(); } Select correct answer (single choice) d.Uno::foo(); d.Due::foo(); d->Uno::foo(); d->Due::foo();

d.Uno::foo();

What is the output of this program if the string "bar" is supplied as input? #include <iostream> #include <string> using namespace std; int main() { string s1 = "foo"; string s2; getline(cin,s2); cout << s2.append(s1); return( 0 ); } Select correct answer (single choice) It prints: foo It prints: bar It prints: foobar It prints: barfoo

foo

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int a = 0; if (++a == 1) { cout << (a >> 1); } else { cout << (a); } return 0; } Select correct answer (single choice) None of these It prints: 2 It prints: 1 It prints: 0

it prints 0

hich code, inserted into the Class, generates the output "abcd"? #include <iostream> using namespace std; class Class { public: static char value; Class() { value++; }; ~Class () { value++; }; //insert code here void print() { cout << value;} }; char Class::value = 'a'; int main () { Class a,*b; b = new Class(); b->set('a'); b->print(); delete b; a.print(); a.set('c'); a.print(); a.set(); a.print(); return 0; } Select correct answer (single choice) void set() { value = 'd'; } void set(char c = 'd') { value = c; } void set(char c) { cout << c; } void set(char c) { value = c; }

void set(char c = 'd') { value = c; }

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { double dbl = -5.55; cout << (int)dbl; } Select correct answer (single choice) -0 -5 -5.5 -6

-5

#include <iostream> using namespace std; struct s { float *f; }; void make(s *p, float x = 10) { float *f = new float; *f = sizeof(*f) / sizeof(float) * 10; p->f = f; } int main() { s *ss = new s; make(ss); cout << *(*ss).f; delete ss->f; delete ss; return 0; } Select correct answer (single choice) 20 10 40 80

10

#include <iostream> using namespace std; int fun(int); int main(){ cout << fun(5); return 0; } int fun(int i) { return i*i; } A. 25 B. 5 C. 0 D. 1

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x=0; int *ptr; ptr = &x; cout<<x<<" "<<*ptr; return 0; } A. It prints: 0 0 B. It prints address of ptr C. It prints: 1 D. It prints: 2

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void out(){ cout << "A"; } }; class B : public A { public: void out(){ cout << "B"; } }; int main() { A *a; a = new A(); a -> out(); a = new B(); a -> out(); return 0; } Select correct answer (single choice) It prints: BA It prints: AA It prints: AB It prints: BB

AA

Which container provides random access iterators? a) vector b) deque c) sort d) Both a & b

Answer D

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

Answer:d Explanation:Because these are the types used to declare variables and so these can be declared as constants.

What does the following statement mean? void a; a) variable a is of type void b) a is an object of type void c) declares a variable with value a d) flags an error

Answer:d Explantion:There are no void objects.

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; }; class B : public A { string name; public: void set() { y = 2; z = 3; } void Print() { cout << y << z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 123 B. It prints: 000 C. It prints: 23 D. It prints: 12

C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class First{ string *s; public: First() { s = new string("Text");} ~First() { delete s;} void Print(){ cout<<*s;} }; int main(){ First FirstObject; FirstObject.Print(); FirstObject.~First(); } A. It prints: Text B. Compilation error C. Runtime error. D. None of these

C

#include <iostream> #include <sstream> #include <string> using namespace std; int main(void){ string s; s = "Test"; s.resize (s.size() ? 1); cout<<s<<" "<<s.size(); return 0; } A. It prints: Test 4 B. It prints: Test 3 C. Compilation error D. It prints: Tes 3

D

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x = -2, y; float f = 2.5, g; g = x; y = f; cout << (int)g / y; return 0; } Select correct answer (single choice) It prints: 1 It prints: -0.8 It prints: -1 It prints: 0.8

It prints -1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class One { public: void out(){ cout<<"One";} }; int main() { One arr[2]; for(int i = 0; i < 1; i++) arr[i].out(); } Select correct answer (single choice) It prints: OneOne Runtime error Compilation error It prints: One

One

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int compare(int, int); int main() { int x = compare(10, 20); cout << x; return 0; } int compare(int i, int j) { return i<j; } A. It prints: 0 B. It prints: 2 C. It prints: 1 D. It prints: 10

Return: C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class One { char value; public: One() { value = 'A'; } One(char v) : value(v) {} void set(char c) {this -> value = c; } void set() { this -> value = 'd'; } char get(){ return value; } }; int main() { One o1,*o2; o2 = new One('b'); One *p; p = &o1; p -> set(); p = o2; p -> set('c'); cout << o2->get() - o1.get(); return 0; } Select correct answer (single choice) Compilation fails It prints: -1 It prints: 0 It prints: 1

-1

What is the output of the program given below? #include <iostream> using namespace std; int main () { int i = 0; cout << i; { int i = 1; cout << i; } { int i = 2; } cout << i; return 0; } Select correct answer (single choice) None of these 010 012 120

010

#include <iostream> using namespace std; int fun(long a) { return a / a; } int fun(int a) { return 2 * a; } int fun(double a = 3.0) { return a; } int main() { cout << fun(1000000000L) << fun (1L) << fun(1.f); return 0; } Select correct answer (single choice) 333 444 222 111

111

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class C1 { friend class C2; protected: int y; public: int z; private: int x; public: C1() { x = y = z = 11; } }; class C2 { public: C1 a; C2 () { a.x = 22; }; void foo() { cout << a.x << a.y << a.z; } }; int main() { C2 c; c.foo(); return 0; } Select correct answer (single choice) It prints: 221111 It prints: 111122 Compilation fails It prints: 112211

221111

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = {2, 4, 6, 8, 10}; vector<int> v(myints, myints + 5); make_heap (v.begin(),v.end()); cout << v.front() << '\n'; return 0; } a) 10 b) 20 c) 4 d) 8

:a Explanation:In this program, We are printing the maximum value in the heap. Output: $ g++ heap2.cpp $ a.out 10

How many types are there in binary heaps? a) 1 b) 2 c) 3 d) 4

:b Explanation:There are two types of heaps. They are min and max heap.

What is meant by heap? a) Used for fast reterival of elements b) Used for organising the elements c) Both a & b d) None of the mentioned

:c Explanation:A heap is a way to organize the elements of a range that allows for fast retrieval of the element.

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main (){ int myints[]={ 10, 20, 30, 40, 50 }; vector<int> myvector (4, 99); iter_swap(myints, myvector.begin()); iter_swap(myints + 3,myvector.begin() + 2); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; } a) 10 b) 10 40 c) 10 99 40 99 d) None of the mentioned

:c Explanation:In this program, We are swapping the certain values in two vectors by using iter_swap. Output: $ g++ msa1.cpp $ a.out 10 99 40 99

#include <iostream> #include <string> using namespace std; class B; class A { int age; public: A () { age=5; }; friend class B; }; class B { string name; public: B () { name="Bob"; }; void Print(A ob) { cout << name << ob.age; } }; int main () { A a; B b; b.Print(a); return 0; } A. It prints: Bob5 B. It prints: Bob C. It prints: 5 D. None of these

A

#include <iostream> #include <string> using namespace std; int main() { string s1="Wo"; string s2; s2 = s1; string s3; s3 = s2.append("rldHello"); cout << s3; return( 0 ); } A. It prints: WorldHello B. It prints: HelloWo C. It prints: World D. It prints: Hello

A

#include <iostream> #include <string> using namespace std; int main() { string s; getline( cin, s ); cout << s << " " << s.length(); return( 0 ); } A. It prints: test 4 B. It prints: test C. It prints: test 5 D. It prints: 4

A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { protected: int y; public: int x; int z; A() { x=2; y=2; z=3; } A(int a, int b) : x(a), y(b) { z = x ? y;} void Print() { cout << z; } }; int main () { A a(2,5); a.Print(); return 0; } A. It prints: ?3 B. It prints: 2 C. It prints: 6 D. It prints: 5

A

What is the output of this program? #include <iostream> using namespace std; int main() { int n = 5; void *p = &n; int *pi = static_cast<int*>(p); cout << *pi << endl; return 0; } a) 5 b) 6 c) compile time error d) runtime error

Answer:a Explanation:We just casted this from void to int, so it prints 5 Output: 5

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 View Answer

Answer:b Explanation:By casting the pointer to another data type, it can dereferenced from void pointer.

Which is also called as abstract class? a) virtual function b) pure virtual function c) derived class d) None of the mentioned

Answer:b Explanation:Classes that contain at least one pure virtual function are called as abstract base classes.

1. How many kinds of classes are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two kinds of classes in c++. They are absolute class and concrete class.

Which of the following implements the module in the program? a) macro b) header files c) both of the mentioned d) none of the mentioned

Answer:b Explanation:We can include the group of code by using the #include header file.

Which value is placed in the base class? a) derived values b) default type values c) both a & b d) None of the mentioned

Answer:b Explanation:We can place the default type values in a base class and overriding some of them through derivation.

Which is called on allocating the memory for array of objects? a) destructor b) constructor c) method d) None of the mentioned

Answer:b Explanation:When you allocate memory for an array of objects, the default constructor must be called to construct each object. If no default constructor exists, you're stuck needing a list of pointers to objects.

What is the output of this program? #include <iostream> using namespace std; int main() { int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24}; cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]]; return 0; } a) 15 18 21 b) 21 21 21 c) 24 24 24 d) Compile time error

Answer:b Explanation:a[1][2] means 1 * (4)+2 = 6th element of an array staring from zero. Output: $ g++ point.cpp $ a.out 21 21 21

What is the ability to group some lines of code that can be included in the program? a) specific task b) program control c) modularization d) macros

Answer:c EXplanation:Modularization is also similar to macros but it is used to build large projects.

Which header file is used to manipulate the vector algebra in c++? a) math b) cmath c) vmath d) None of the mentioned

Answer:c Explanation: vmath is set of C++ classes for Vector and Matrix algebra used in the programs.

What is the output of this program? #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; } a) 2 5 10 b) 2 4 5 c) 2 6 14 d) none of the mentioned

Answer:c Explanation:Because we multiplied the values by 2 in the copy function. Output: $ g++ arg6.cpp $ a.out x = 2,y = 6,z = 14

What is the output of this program? #include <iostream> using namespace std; int main () { int n; n = -77; cout.width(4); cout << internal << n << endl; return 0; } a) 77 b) -77 c) - 77 d) None of the mentioned

Answer:c Explanation:In this program, We are using the internal function and moving the 77 to one position. Output: $ g++ ous3.cpp $ a.out - 77

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 mentioned

Answer:c Explanation:None.

Which are the parameters for the content of the buffer? a) start b) finish c) Both a & b d) None of the mentioned

Answer:c Explanation:The contents of the buffer are initialized using the values from the iterator range supplied to the constructor by the start and finish parameters.

What are the mandatory part to present in function pointers? a) & b) retrun values c) data types d) none of the mentioned

Answer:c Explanation:The data types are mandatory for declaring the variables in the function pointers.

Identify the user-defined types from the following? a) enumeration b) classes c) both a and b d) int

Answer:c Explanation:They must be defined by the users before use unlike the other types which are readily available.

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 10; if (a < 15) { time: cout << a; goto time; } break; return 0; } a) 1010 b) 10 c) infinitely print 10 d) compile time error

Answer:d Explanation:Because the break statement need to be presented inside a loop or a switch statement.

What is the output of this program? #include <iostream> #include <vector> #include <algorithm> using namespace std; void show(const vector<int>& vi) { for (size_t i = 0; i < vi.size(); ++i) cout << vi[i]; cout << endl; } int main() { vector<int> vi; vi.push_back(3); vi.push_back(5); vi.push_back(5); sort(vi.begin(), vi.end()); show(vi); while(next_permutation(vi.begin(), vi.end())) show(vi); return 0; } a) 355 b) 535 c) 553 d) All of the mentioned

Answer:d Explanation:In this program, We are finding the permutation for the given value. Output: $ g++ perm4.cpp $ a.out 355 535 553

What is the output of this program? #include <iostream> using namespace std; template <typename T, int count> void loopIt(T x) { T val[count]; for(int ii = 0; ii < count; ii++) { val[ii] = x++; cout << val[ii] << endl; } }; int main() { float xx = 2.1; loopIt<float, 3>(xx); } a) 2.1 b) 3.1 c) 4.1 d) 2.1 3.1 4.1

Answer:d Explanation:In this program, We are using the non-type template parameter to increment the value in the function template. Output: $ g++ farg4.cpp $ a.out 2.1 3.1 4.1

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 10; if (a < 10) { for (i = 0; i < 10; i++) cout << i; } else { cout << i; } return 0; } a) 0123456789 b) 123456789 c) 0 d) error

Answer:d Explanation:We will get compilation error because 'i' is an undeclared identifier.

How many bits of memory needed for internal representation of class? a) 1 b) 2 c) 4 d) no memory needed

Answer:d Explanation:classes that contain only type members, non virtual function members, and static data members do not require memory at run time.

Pick out the correct objects about the instantiation of output stream. a) cout b) cerr c) clog d) All of the mentioned

Answer:d Explanation:cout, cerr and clog are the standard objects for the instantiation of output stream class.

Pick the odd one out a) array type b) character type c) boolean type d) integer type

Array type is not the basic type and it is constructed using the basic type.

What is the output of the following program? #include <iostream> using namespace std; int main() { int num1 = 10; float num2 = 20; cout << sizeof(num1 + num2); return 0; } a) 2 b) 4 c) 8 d) garbage

View Answer Answer:b Explanation:In this program, integer is converted into float. Therefore the result of num1 and num2 is float. And it is returning the size of the float. Output: 4

In which type of storage location are the vector members stored? a) Contiguous storage locations b) Non-contiguous storage locations c) Both a & b d) None of the mentioned

answer A Explanation:Vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements

#include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; A() { x=1; y=2; z=3; } }; class B : public A { string z; public: void set() { y = 4; z = "John"; } void Print() { cout << y << z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 4John B. It prints: 2John C. It prints: 23 D. It prints: 43

A

#include <iostream> #include <string> using namespace std; class A { public: string s; A(string s) { this?>s = s; } }; class B { public: string s; B (A a) { this?>s = a.s; } void print() { cout<<s; } }; int main() { A a("Hello world"); B b=a; b.print(); } A. It prints: Hello world B. It prints: Hello C. Compilation error D. None of these

A

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

Answer:d Explanation:None.

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;

Answer:d Explanation:None.

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A no parameters";} A(string s) { cout << "A string parameter";} A(A &a) { cout << "A object A parameter";} }; class B : public A { public: B() { cout << "B no parameters";} B(string s) { cout << "B string parameter";} B(int s) { cout << "B int parameter";} }; int main () { A a2("Test"); B b1(10); B b2(b1); return 0; } A. It prints: A no parametersA no parametersB string parameter B. It prints: A string parameterA no parametersB int parameterA object A parameter C. It prints: A no parametersB string parameter D. It prints: A no parametersA no parameters

B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: int x; }; class B : public A { public: B() { x=1;} B(int x) {this?>x = x;} }; int main () { B c1; B c2(10); cout << c1.x; cout << c2.x; return 0; } A. It prints: 010 B. It prints: 110 C. It prints: 00 D. It prints: 1

B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class complex{ double re, im; public: complex() : re(1),im(0.4) {} complex operator+(complex &t); void Print() { cout << re << " " << im; } }; complex complex::operator+ (complex &t){ complex temp; temp.re = this?>re + t.re; temp.im = this?>im + t.im; return temp; } int main(){ complex c1,c2,c3; c3 = c1 + c2; c3.Print(); } A. It prints: 1 0.4 B. It prints: 2 0.8 C. It prints: 0 0 D. Garbage value

B

Which code, inserted at line 15, generates the output "5 Bob"? #include <iostream> #include <string> using namespace std; class B; class A { int age; public: A () { age=5; }; friend void Print(A &ob, B &so); }; class B { string name; public: B () { name="Bob"; }; //insert code here }; void Print(A &ob, B &so) { cout<<ob.age << " " << so.name; } int main () { A a; B b; Print(a,b); return 0; } A. friend void Print(A ob, B so); B. friend void Print(A &ob, B &so); C. friend void Print(A *ob, B *so); D. None of these

B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A0 ";} A(string s) { cout << "A1";} }; class B : public A { public: B() { cout << "B0 ";} B(string s) { cout << "B1 ";} }; class C : private B { public: C() { cout << "C0 ";} C(string s) { cout << "C1 ";} }; int main () { B b1; C c1; return 0; } A. It prints: A0 B0 A0 B1 A0 C0 A0 C1 B. It prints: B0 B1 C0 C1 C. It prints: A0 B0 A0 B0 C0 D. It prints: B0 B1

C

Which code, inserted at line 10, generates the output "Hello World"? #include <iostream> #include <string> using namespace std; string fun(string, string); int main() { string s="Hello"; string *ps; ps = &s; //insert code here return 0; } string fun(string s1, string s2) { return s1+s2; } A. cout << fun(" World"); B. cout << fun(*ps); C. cout << fun("Hello"); D. cout << fun("Hello", " World");

D

What is the output of the program? #include <iostream> using namespace std; int main(){ int tab[4]={10,20,30,40}; tab[1]=10; int *p; p=&tab[0]; cout<<*p; return 0; } A. It prints: 10 B. It prints: 20 C. It prints: 11 D. It prints: 30

A

What will happen when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const char *s; char str[] = "Hello "; s = str; while(*s) { cout << *++s; *s++; } return 0; } A. It will print:"el " B. The code will not compile. C. It will print:"Hello " D. It will print garbage value

A

How many types does functions fall depends on modularization? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of functions.They are program control and specific task.

How many types of macros are there in c++? a) 1 b) 2 c) 3 4) 4

Answer:b Explanation:There are two types of macros. They are object-like and function-like.

How many types of templates are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of templates. They are function template and class template.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c_double(2, 3); complex<int> c_int(4, 5); c_double *= 2; c_double = c_int; cout << c_double; return 0; } a) (2, 3) b) (4, 5) c) (8, 15) d) None of the mentioned

Answer:b Explanation:We are just copying the value of c_int into c_double, So it's printing as (4,5). Output: $ g++ comp1.cpp $ a.out (4,5)

How to declare the complex number? a) (3,4) b) complex(3,4) c) (3,4i) d) None of the mentioned

Answer:b Explanation:We can declare the complex number by using complex(3,4) where 3 is a real number and 4 is imaginary part.

How do we represent a wide character of the form wchar_t? a) L'a' b) l'a' c) L[a] d) la

Answer:a Explanation: A wide character is always indicated by immediately preceding the character literal by an L.

What does a escape code represent? a) alert b) backslash c) tab d) form feed

Answer:a Explanation: Because a is used to produce a beep sound.

Is bool a fundamental datatype in C++? a) Yes b) No, it is a typedef of unsigned char c) No, it is an enum of {false,true} d) No, it is expanded from macros

Answer:a Explanation: C++ has bool as a fundamental data type

Which of the following is not one of the sizes of the floating point types? a) short float b) float c) long double d) double

Answer:a Explanation:Floating point types occur in only three sizes-float, long double and double.

How to declare a wide character in string literal? a) L prefix b) l prefix c) W prefix d) none of the mentioned

Answer:a Explanation:It can turn this as wide character instead of narrow characters.

What is the range of the floating point numbers? a) -3.4E+38 to +3.4E+38 b) -3.4E+38 to +3.4E+34 c) -3.4E+38 to +3.4E+36 d) -3.4E+38 to +3.4E+32

Answer:a Explanation:None.

What is the output of this program? #include <iostream> using namespace std; int main() { int i; char *arr[] = {"C", "C++", "Java", "VBA"}; char *(*ptr)[4] = &arr; cout << ++(*ptr)[2]; return 0; } a) ava b) java c) c++ d) compile time error

Answer:a) ava Explanation:In this program we are moving the pointer from first position to second position and printing the remaining value. Output: ava

How many characters are specified in the ASCII scheme? a) 64 b) 128 c) 256 d) none of the mentioned

Answer:b Explanation: None.

What will be output of this program? #include <iostream> using namespace std; int main() { int i = 3; int l = i / -2; int k = i % -2; cout << l << k; return 0; } a) compile time error b) -1 1 c) 1 -1 d) implementation defined

Answer:b Explanation: Sign of result of mod operation on negative numbers is sign of the dividend.

Which of the following statements are true? int f(float) a) f is a function taking an argument of type int and retruning a floating point number b) f is a function taking an argument of type float and returning a integer. c) f is a function of type float d) none of the mentioned

Answer:b Explanation: The argument that is passed to a function f is of float type and the function finally retruns a value that id is of integer type.

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

Answer:b Explanation:In the above declaration the variable p is array not pointer.

What is the output of this program? #include <iostream> using namespace std; int main() { int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24}; cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]]; return 0; } a) 15 18 21 b) 21 21 21 c) 24 24 24 d) Compile time error

Answer:b Explanation:a[1][2] means 1 * (4)+2 = 6th element of an array staring from zero. Output: 21 21 21

What happens when a null pointer is converted into bool? a) An error is flagged b) bool value evaluates to true c) bool value evaluates to false d) the statement is ignored

Answer:c Explanation: A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zero valued pointer converts to false.

Select the right option. Given the variables p, q are of char type and r, s, t are of int type 1. t = (r * s) / (r + s); 2. t = (p * q) / (r + s); a) 1 is true but 2 is false b) 1 is false and 2 is true c) both 1 and 2 are true d) both 1 and 2 are false

Answer:c Explanation: Every character constant has an integer value. Also char belongs to the integral type hence arithmetic and logical operations can be performed on them.

Is the size of character literals different in C and C++? a) Implementation defined b) Can't say c) Yes, they are different d) No, they are not different

Answer:c Explanation: In C++, sizeof('a') == sizeof(char) == 1. In C however, sizeof('a') == sizeof(int).

What is the output of the following program? #include <iostream> using namespace std; int f(int p, int q) { if (p > q) return p; else return q; } main() { int a = 5, b = 10; int k; bool x = true; bool y = f(a, b); k =((a * b) + (x + y)); cout << k; } a) 55 b) 62 c) 52 d) none of the mentioned

Answer:c Explanation: None.

Which of these expressions will isolate the rightmost set bit? a) x = x & (~x) b) x = x ^ (~x) c) x = x & (-x) d) x = x ^ (-x)

Answer:c Explanation: None.

Pick the odd one out. a) integer, character, boolean, floating b) enumeration, classes c) integer, enum, void d) arrays, pointer, classes

Answer:c Explanation: Option a consists of all fundamental types, option b consists of user-definied types and option d consists of derived types but option c is a mixture.

For what values of the expression is an if-statement block not executed? a) 0 and all negative values b) 0 and -1 c) 0 d) 0, all negative values, all positive values except 1

Answer:c Explanation: The if-statement block is only not executed when the expression evaluates to 0. It's just syntactic sugar for a branch-if-zero instruction.

What will be the output of this program? #include <iostream> using namespace std; int main() { char c = 74; cout << c; return 0; } a) A b) N c) J d) I

Answer:c Explanation: The literal value for 74 is J. So it will be printing J.

What is the output of the following program? #include <iostream> using namespace std; int main() { float i = 123.0f; cout << i << endl; return 0; } a) 123.00 b) 1.23 c) 123 d) compile time error

Answer:c Explanation:The value 123 is printed because of its precision. 123

Which of the following is a valid floating point literal? a) f287.333 b) F287.333 c) 287.e2 d) 287.3.e2

Answer:c Explanation:To make a floating point literal, we should attach a suffix of 'f' or 'F' and there should not be any blank space.

What is the output of this program? #include <iostream> using namespace std; int main() { int const p = 5; cout << ++p; return 0; } a) 5 b) 6 c) Error d) None of the mentioned

Answer:c Explanation:We cannot modify a constant integer value.

Which of the following is illegal? a) int *ip; b) string s, *sp = 0; c) int i; double* dp = &i; d) int *pi = 0;

Answer:c Explanation:dp is initialized int value of i.

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *arr + 9; return 0; } a) 12 b) 5 c) 13 d) error

Answer:c Explantion:In this program, we are adding the value 9 to the initial value of the array, So it's printing as 13. Output: 13

What is the output of this program? #include <stdio.h> using namespace std; int main() { int a = 5, b = 10, c = 15; int arr[3] = {&a, &b, &c}; cout << *arr[*arr[1] - 8]; return 0; } a) 15 b) 18 c) garbage value d) compile time error

Answer:compile time error Explantion: The conversion is invalid in this array. So it will arise error. The following compilation error will be raised: cannot convert from 'int *' to 'int'

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

Answer: -30 Explanation:It's just printing the negative value of the concern element.

The value 132.54 can represented using which data type? a) double b) void c) int d) bool

Answer:a Explanation: The given value is with decimal points, so float or double can be used.

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

Answer:a Explanation:* is to be grouped with the variables not the data types.

What is the output of this program? #include <iomanip> #include <iostream> using namespace std; int main() { cout << setprecision(17); double d = 0.1; cout << d << endl; return 0; } a) 0.11 b) 0.10000000000000001 c) 0.100001 d) compile time error

Answer:b Explanation: The double had to truncate the approximation due to it's limited memory, which resulted in a number that is not exactly 0.1. Output: 0.10000000000000001

Which of the two operators ++ and — work for the bool datatype in C++? a) None b) ++ c) — d) Both

Answer:b Explanation: Due to history of using integer values as booleans, if an integer is used as a boolean, then incrementing will mean that whatever its truth value before the operation, it will have a truth-value of true after it. However, it's not possible to predict the result of — given knowledge only of the truth value of x, as it could result in false.

Find the odd one out: a) std::vector<int> b) std::vector<short> c) std::vector<long> d) std::vector<bool>

Answer:d Explanation: std::vector<bool> is a specialized version of vector, which is used for elements of type bool and optimizes for space. It behaves like the unspecialized version of vector and the storage is not necessarily an array of bool values, but the library implementation may optimize storage so that each value is stored in a single bit.

Which of the following belongs to the set of character types? a) char b) wchar_t c) only a d) both a and b

Answer:d Explanation: wchar_t and char is used to represent wide character and character.

It is guaranteed that a ____ has atleast 8bits and a ____ has atleast 16 bits. a) int, float b) char, int c) bool, char d) char, short

Answer:d Explanation:None.

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

There are three output stream classes in c++. They are ostream, ofstream and ostrstream.

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); }

Answer:ABCDEFGHIJ Explanation:Each time we are assigning 65 + i. In first iteration i = 0 and 65 is assigned. So it will print from A to J.

What is the output of this program? #include <iostream> using namespace std; int main() { float f1 = 0.5; double f2 = 0.5; if (f1 == 0.5f) cout << "equal"; else cout << "not equal"; return 0; } a) equal b) not equal c) compile time error d) runtime error

Answer:a Explanation: 0.5f results in 0.5 to be stored in floating point representations. Output: equal

What is the output of this program? #include <iostream> using namespace std; void swap(int &a, int &b); int main() { int a = 5, b = 10; swap(a, b); cout << "In main " << a << b; return 0; } void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; cout << "In swap " << a << b; } a) In swap 105 In main 105 b) In swap 105 In main 510 c) In swap 510 In main 105 d) none of the mentioned

Answer:a Explanation:As we are calling by reference the values in the address also changed. So the main and swap values also changed. Output: In swap 105 In main 105

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.5664 b) 13.5664 c) 10 d) compile time error

Answer:a Explanation:In this program, we are finding the area of the circle by using concern formula. Output: 12.5664

hat will be the output of this program? #include <iostream> using namespace std; int main() { int a = 8; cout << "ANDing integer 'a' with 'true' :" << a && true; return 0; } a) ANDing integer 'a' with 'true' :8 b) ANDing integer 'a' with 'true' :0 c) ANDing integer 'a' with 'true' :1 d) None of the mentioned

Answer:a Explanation: None.

What is the output of the following program? #include <iostream> using namespace std; int main() { int x = -1; unsigned int y = 2; if(x > y) { cout << "x is greater"; } else { cout << "y is greater"; } } a) x is greater b) y is greater c) Implementation defined d) Arbitrary

Answer:a Explanation: x is promoted to unsigned int on comparison. On conversion x has all bits set, making it the bigger one.

Which of the following correctly declares an array? a) int array[10]; b) int array; c) array{10}; d) array array[10];

Answer:a Explanation:Because array variable and values need to be declared after the datatype only.

What is the output of this program? #include <iostream> using namespace std; int main() { float num1 = 1.1; double num2 = 1.1; if (num1 == num2) cout << "stanford"; else cout << "harvard"; return 0; } a) harvard b) stanford c) compile time error d) runtime error

Answer:a Explanation:Float store floating point numbers with 8 place accuracy and requires 4 bytes of Memory. Double has 16 place accuracy having size of 8 bytes. Output: harvard

What is the output of this program? #include <iostream> using namespace std; int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p + 4) = 50; for (int n = 0; n < 5; n++) cout << numbers[n] << ","; return 0; } a) 10,20,30,40,50, b) 1020304050 c) compile error d) runtime error

Answer:a Explanation:In this program, we are just assigning a value to the array and printing it and immediately dereferencing it. Output: 10,20,30,40,50,

Size of C++ objects are expressed in terms of multiples of the size of a ____ and the size of a char is ____. a) char, 1 b) int, 1 c) float, 8 d) char, 4

Answer:a Explanation:None.

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

Answer:a Explanation:None.

What is a array? a) An 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

Answer:a Explanation:None.

What is the output of this program? #include <iostream> using namespace std; void print (char * a) { cout << a << endl; } int main () { const char * a = "Hello world"; print(const_cast<char *> (a) ); return 0; } a) Hello world b) Hello c) world d) compile time error

Answer:a Explanation:None.

Which reference modifier is used to define reference variable? a) & b) $ c) # d) none of the mentioned

Answer:a Explanation:None.

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

Answer:a Explanation:Pointer ptr points to string 'fg'. So it prints fg. fg

Which of the following accesses the seventh element stored in array? a) array[6]; b) array[7]; c) array(7); d) array;

Answer:a Explanation:The array location starts from zero, So it can accessed by array[6].

When a language has the capability to produce new data type mean, it can be called as a) overloaded b) extensible c) encapsulated d) reprehensible

Answer:b Explanation: Extensible is used to add new features to C++.

Which type is best suited to represent the logical values? a) integer b) boolean c) character d) all of the mentioned

Answer:b Explanation: Logical values can be either true or false, so the boolean type is suited for it.

What is the value of p? #include <iostream> using namespace std; int main() { int p; bool a = true; bool b = false; int x = 10; int y = 5; p = ((x | y) + (a + b)); cout << p; return 0; } a) 0 b) 16 c) 12 d) 2

Answer:b Explanation: None.

Which of the following statements are false? a) bool can have two values and can be used to express logical expressions. b) bool cannot be used as the type of the result of the function. c) bool can be converted into integers implicitly d) a bool value can be used in arithemetic expressions.

Answer:b Explanation: None.

Which of these expressions will make the rightmost set bit zero in an input integer x? a) x = x | (x-1) b) x = x & (x-1) c) x = x | (x+1) d) x = x & (x+1)

Answer:b Explanation: None.

What is the value of the bool? bool is_int(789.54) a) True b) False c) 1 d) none of the mentioned

Answer:b Explanation: The given number is a double not an integer, so the function returns 0 which is boolean false.

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

Answer:b Explanation:Assigning to refrence changes the object to which the refrence is bound.

What is the index number of the last element of an array with 9 elements? a) 9 b) 8 c) 0 d) Programmer-defined

Answer:b Explanation:Because the first element always starts at 0. So it is on 8 position.

What does a reference provide? a) Alternate name for the class b) Alternate name for the variable c) Alternate name for the pointer d) none of the mentioned

Answer:b Explanation:Because we are pointing memory address using temp variable

Identify the incorrect statement a) reference is the alternate name of the object b) A reference value once defined can be reassigned c) A reference value once defined cannot be reassigned d) none of the mentioned

Answer:b Explanation:Reference is a thing which points to valid memory address, so it can't be redesigned.

Implementation dependent aspects about an implementation can be found in ____ a) <implementation> b) <limits> c) <limit> d) <numeric>

Answer:b Explanation:The limit header holds the details of the machine dependent details.

The size of an object or a type can be determined using which operator? a) malloc b) sizeof c) malloc d) calloc

Answer:b Explanation:The sizeof operator gives the size of the object or type.

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 9; int & aref = a; a++; cout << "The value of a is " << aref; return 0; } a) 9 b) 10 c) error d) 11

Answer:b Explanation:The value is declared and it is post incremented, so it's value is 10. 10

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

Answer:c Explanation: Because the const is used to declare non-changeable values only.

The size_t integer type in C++ is? a) Unsigned integer of at least 64 bits b) Signed integer of at least 16 bits c) Unsigned integer of at least 16 bits d) Signed integer of at least 64 bits

Answer:c Explanation: The size_t type is used to represent the size of an object. Hence, it's always unsigned. According to the language specification, it is at least 16 bits.

What is the output of this program? #include <stdio.h> int main() { char a = '\012'; printf("%d", a); return 0; } a) Compiler error b) 12 c) 10 d) Empty

Answer:c Explanation: The value '\012' means the character with value 12 in octal, which is decimal 10.

What will be output of this function? int main() { register int i = 1; int *ptr = &i; cout << *ptr; return 0; } a) 0 b) 1 c) Compiler error may be possible d) Runtime error may be possible

Answer:c Explanation: Using & on a register variable may be invalid, since the compiler may store the variable in a register, and finding the address of it is illegal.

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << arr; return 0; } a) 4 b) 5 c) address of arr d) 7

Answer:c Explanation:As we couted to print only arr, it will print the address of the array. Output: 0xbfb1cff

Which of three sizes of floating point types should be used when extended precision is required? a) float b) double c) long double d) extended float

Answer:c Explanation:Float for single precision, double for double precision and long double for extended precision.

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)

Answer:c Explanation:None.

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

Answer:c Explanation:None.

How the constants are declared? a) const keyword b) #define preprocessor c) both a and b d) None of the mentioned

Answer:c Explanation:The const will declare with a specific type values and #define is used to declare user defined constants.

0946, 786427373824, 'x' and 0X2f are _____, _____, ____ and _____ literals respectively a) decimal, character,octal, hexadecimal b) octal, hexadecimal, character, decimal c) hexadecimal, octal, decimal, character d) octal, decimal, character, hexadecimal

Answer:d Explanation: Literal integer constants that begin with 0x or 0X are interpreted as hexadecimal and the ones that begin with 0 as octal. The character literal are written within ".

Which of the following statement is not true about preprocessor directives? a. These 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

Answer:d Explanation: None.

Which of these expressions will return true if the input integer v is a power of two? a) (v | (v + 1)) == 0; b) (~v & (v - 1)) == 0; c) (v | (v - 1)) == 0; d) (v & (v - 1)) == 0;

Answer:d Explanation: Power of two integers have a single set bit followed by unset bits.

What is the value of the following 8-bit integer after all statements are executed? int x = 1; x = x << 7; x = x >> 7; a) 1 b) -1 c) 127 d) Implementation defined

Answer:d Explanation: Right shift of signed integers is undefined, and has implementation-defined behaviour.

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

Answer:d Explanation:A pointer can be in only 3 states a,b and c.

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

Answer:d Explanation:Array element cannot be address of auto variable. It can be address of static or extern variables.

Which value we cannot assign to reference? a) integer b) floating c) unsigned d) null

Answer:d Explanation:If it can be assigned with a null value means, it is a copy of pointer.

Which is correct with respect to size of the datatypes? a) char > int < float b) int < char > float c) char < int < float d) char < int < double

Answer:d Explanation:The char has lesser bytes than int and int has lesser bytes than double whereas int and float can potentially have same sizes.

Which is used to indicate single precision value? a) F or f b) L or l c) either a or b d) neither a or b

Answer:a Explanation:None.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int sub(int x, int y) { x -= y; return x; } int main() { int a = 0, b = 1, c, d; c = sub(a,b); d = sub(c,b); cout << c << d; return 0; } Select correct answer (single choice) It prints: 1-2 It prints: -1-2 It prints: 12 It prints: -12

-1-2

#include <iostream> using namespace std; int fun(float a, float b) { return a / b; } int main() { cout << fun(fun(1.0,2.0),fun(2.0,1.0)); return 0; } Select correct answer (single choice) 1 -1 2 0

0

#include <iostream> using namespace std; int main() { float f[2]; float *p1 = f, *p2 = p1 + 1; cout << (p2 - p1) / sizeof(float); return 0; } Select correct answer (single choice) 2 3 1 0

0

Which keyword is used to access the variable in namespace? a) using b) dynamic c) const d) static

Answer:a Explanation:None.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; bool compare(bool t, bool u) { return t < u; } int main() { cout << compare(true,false); return 0; } Select correct answer (single choice) It prints: 1 It prints: false It prints: 0 It prints: true

0

What happens when you attempt to compile and run the following code? #include <iostream> void fun(int *i) { *i = *i >> *i - 1; } using namespace std; int main() { int i = 2; fun(&i); cout << i; return 0; } Select correct answer (single choice) It prints: 4 It prints: 2 It prints: 1 It prints: 0

1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define CALL(param) { if(param) cout << param++; } int main() { int i = 1; CALL(i); cout << i; return 0; } Select correct answer (single choice) It prints: 2 It prints: 1 It prints: 12 It prints: 11

12

What is the output of the program given below ? #include <iostream> using namespace std; int main () { enum answer { yes, no, whoknows }; enum answer a[3]; a[0] = no; a[2] = yes; a[1] = whoknows; for(int i = 0; i < 3; i++) cout << a[i]; return 0; } Select correct answer (single choice) It prints: 210 It prints: 120 It prints: 102 It prints: 201

120

#include <iostream> using namespace std; int fun(int a, int b) { return a + b; } int fun(int a, char b) { return b - a; } int fun(float a, float b) { return a * b; } int main() { cout << fun(1,0) << fun('a','c') << fun(2.f,2.f); return 0; } Select correct answer (single choice) 124 481 012 248

124

#include <iostream> using namespace std; int fun(int p1 = 1, int p2 = 1) { return p2 << p1; } int main() { cout << fun(fun(),fun(2)); return 0; } Select correct answer (single choice) 16 32 4 8

16

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 2; if (i--==1) cout << i; else cout << i + 1; return 0; } Select correct answer (single choice) It prints: 1 It prints: 2 It prints: i + 1 It prints: 3

2

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; namespace OuterSpace { int x = 1; int y = 2; } namespace InnerSpace { float x = 3.0; float y = 4.0; } int main () { { using namespace InnerSpace; cout << x << " "; }{ using namespace OuterSpace; using InnerSpace::y; cout << y; } return 0; } Select correct answer (single choice) Compilation error It prints: 3 2 It prints: 3 1 It prints: 3 4

3 4

#include <iostream> using namespace std; int f1(int a) { return ++a; } int f2(int &a) { return ++a; } int f3(int *a) { return *a + 1; } int main() { int value = 2; cout << f1(value); cout << f2(value); cout << f3(&value); return 0; } Select correct answer (single choice) 456 334 333 445

334

What is the output of the program given below? #include <iostream> using namespace std; void foo(int &parameter) { parameter *= 2; } int main() { int var = 2; foo(var); cout << var; return 0; } Select correct answer (single choice) 2 8 4 1

4

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 10; float f = 2.5; cout << float(i) / int(f); return 0; } Select correct answer (single choice) It prints: 5 It prints: 0.5 It prints: 1 It prints: 4

5

What will be the output of this program? #include <iostream> #include <string> using namespace std; int boo(int v) { v++; return ++v; } int main() { float x = 3; x = boo(x); cout << x; return 0; } Select correct answer (single choice) It prints: 1 It prints: 3 It prints: 5 It prints: -1

5

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { vector<int> myvector (5); fill (myvector.begin(), myvector.begin() + 4, 5); fill (myvector.begin() + 3,myvector.end() - 2, 8); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; } a) 5 5 5 5 0 b) 8 8 8 8 0 c) 5 8 5 8 0 d) 5 5 5 5 5

:a Explanation:In this program, We filled up all the vector values by using fill method. Output: $ g++ msa.cpp $ a.out 5 5 5 5 0

What kind of object is modifying sequence algorithm? a) Function template b) Class template c) Method d) None of the mentioned

:a Explanation:It is a group of functions and implemented under algorithm header file.

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; bool myfunction (int i,int j) { return (i<j); } int main () { int myints[] = {9, 8, 7, 6, 5}; vector<int> myvector (myints, myints + 5); partial_sort (myvector.begin(), myvector.begin() + 3, myvector.end()); partial_sort (myvector.begin(), myvector.begin() + 2, myvector.end(), myfunction); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; } a) 5 6 7 b) 5 6 7 9 8 c) 9 8 7 6 5 d) None of the mentioned

:b Explanation:In this program, We are partitioning the value by using the partial_sort method. Output: $ g++ heap3.cpp $ a.out 5 6 7 9 8

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = {1, 2, 3, 4 ,5}; vector<int> v(myints, myints + 5); v.push_back(33); push_heap (v.begin(),v.end()); cout << v.front() << '\n'; sort_heap (v.begin(),v.end()); return 0; } a) 1 b) 33 c) 3 d) 44

:b Explanation:In this program, We are pushing a new value into heap and printing it. Output: $ g++ heap1.cpp $ a.out 33

What is the output of this program? #include <iostream> #include <algorithm> using namespace std; int main () { int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 }; int* pbegin = myints; int* pend = myints + sizeof(myints) / sizeof(int); pend = remove (pbegin, pend, 20); for (int* p = pbegin; p != pend; ++p) cout << ' ' << *p; return 0; } a) 10 20 30 b) 10 30 30 10 10 c) 10 20 30 30 d) None of the mentioned

:b Explanation:In this program, We removed the values in the vector by using the remove method. Output: $ g++ msa3.cpp $ a.out 10 30 30 10 10

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = { 10, 20, 30 ,40 }; int * p; p = find (myints, myints + 4, 30); --p; cout << *p << '\n'; return 0; } a) 10 b) 20 c) 30 d) 40

:b Explanation:In this program, We used the find method to find the value before 20. Output: $ g++ msa4.cpp $ a.out 20

How many kind of operation can be applied to transform method in c++? a) 1 b) 2 c) 3 d) 4

:b Explanation:There are two kinds of operations. They are unary and binary operation.

How the sequence of objects can be accessed? a) Iterators b) Pointers c) Both a & b d) None of the mentioned

:c Explanation:A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.

What is the use of middle parameter in rotate method? a) Marks the begining of a sequence b) Marks the ending of a sequence c) Marks the elements in a sequence d) None of the mentioned

:c Explanation:Forward iterator pointing to the element within the range and that can be moved to the first position in the range.

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int myints[] = {10, 20, 30, 5, 15}; vector<int> v(myints, myints + 5); make_heap (v.begin(), v.end()); pop_heap (v.begin(), v.end()); v.pop_back(); v.push_back(99); push_heap (v.begin(), v.end()); sort_heap (v.begin(), v.end()); for (unsigned i = 0; i < v.size(); i++) cout << ' ' << v[i]; return 0; } a) 5 10 b) 5 10 15 20 c) 5 10 15 20 99 d) None of the mentioned

:c Explanation:In this program, We popped out 30 and pushed 99 and then we are sorting that value, So it is printing it. Output: $ g++ heap.cpp $ a.out 5 10 15 20 99

What is the output of this program? #include <iostream> #include <algorithm> #include <vector> #include <functional> using namespace std; int op_increase (int i) { return ++i; } int main () { vector<int> a; vector<int> b; for (int i = 1; i < 4; i++) a.push_back (i * 10); b.resize(a.size()); transform (a.begin(), a.end(), b.begin(), op_increase); transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>()); for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it) cout << ' ' << *it; return 0; } a) 21 b) 41 c) 61 d) All of the mentioned

:d Explanation:In this program, We allocated the values to the vector and then by using transform function, We increased the values. Output: $ g++ msa2.cpp $ a.out 21 41 61

How to protect the heap from affecting the memory? a) Avoid using pointers for associating two data structures b) Embed pointed child objects into the parent object c) Allocate objects in chunks d) All of the mentioned

:d Explanation:None.

In what form does the STL provides heap? a) queue b) list c) vector d) priority_queue

:d Explanation:STL does provide a heap in the form of a std::priority_queue.

What operator is used to remove the duplicates in the range? a) ) b) ^ c) % d) ==

:d Explanation:The function uses operator== to compare the pairs of elements.

#include <iostream> #include <string> using namespace std; class A { protected: int y; public: int x,z; A() : x(1), y(2), z(0) { z = x + y; } A(int a, int b) : x(a), y(b) { z = x + y;} void Print() { cout << z; } }; class B : public A { public: int y; B() : A() {} B(int a, int b) : A(a,b) {} void Print() { cout << z; } }; int main () { A b; b.Print(); return 0; } A. It prints: 3 B. It prints: 0 C. It prints: 1 D. It prints: 2

A

#include <iostream> using namespace std; class A { public: virtual void Print()=0; }; class B:public A { public: virtual void Print() { cout<< "B"; } }; class C:public A { public: virtual void Print() { cout<< "C"; } }; int main() { B ob2; C ob3; A *obj; obj = &ob2; obj?>Print(); obj = &ob3; obj?>Print(); } A. It prints: BC B. It prints: CB C. It prints: CC D. It prints: BB

A

#include <iostream> using namespace std; class A{ public: virtual void Print(){ cout<<"A";} }; class B: public A{ public: void Print(){ cout<< "B";} }; int main(){ A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); } A. It prints: AB B. It prints: AA C. It prints: BA D. It prints: BB

A

#include <iostream> using namespace std; int fun(int x) { return 2*x; } int main(){ int i; i = fun(1) & fun(0); cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. Compilation error

A

#include <iostream> using namespace std; int main (int argc, const char * argv[]){ int x,y; union t { char tab[2]; int i; }; union t u; u.tab[0] = 1; u.tab[1] = 2; u.i = 0; x = u.tab[0]; y = u.tab[1]; cout << x << "," << y << "," << u.i; return 0; } A. compilation fails B. It prints: 0,0,0 C. It prints: 1,2,0 D. None of these

A

#include <iostream> using namespace std; int main() { float x=3.5,y=1.6; int i,j=2; i = x + j + y; cout << i; return 0; } A. It prints: 7 B. It prints: 6 C. It prints: 7,1 D. Compilation error

A

#include <iostream> using namespace std; int op(int x, int y); int main(){ float *pf; float f=0.9; pf=&f; cout << op(1, *pf); return 0; } int op(int x, int y){ return x*y; } A. It prints: 0 B. It prints: 0.5 C. It prints: 1 D. It prints: ?1

A

#include <iostream> using namespace std; void fun(char*); int main() { char t[4]={'0', '1', '2', '3'}; fun(&t[2]); return 0; } void fun(char *a) { cout << *a; } A. It prints: 2 B. It prints: 21 C. It prints: 00 D. It prints: 02

A

#include <iostream> using namespace std; void fun(int); int main(){ int a=0; fun(a); return 0; } void fun(int n){ if(n < 2){ fun(++n); cout << n; } } A. It prints: 21 B. It prints: 012 C. It prints: 0 D. None of these

A

Given: #include <iostream> #include <exception> using namespace std; int main () { try { int * myarray= new int[1000]; } catch (bad_alloc&) { cout << "Error allocating memory"; } catch (exception& e) { cout << "Standard exception"; } catch (...) { cout << "Unknown exception"; } return 0; } What will happen if we use the operator "new" and the memory cannot be allocated? A. It prints: Error allocating memory B. It prints: Standard exception C. It prints: Unknown exception D. Compilation error

A

Point out an error in the program. #include <iostream> using namespace std; int main() { const int x=1; int const *y=&x; cout<<*y; return 0; } A. No error B. Error: unknown pointer conversion C. cannot convert from 'const int *' to 'int *const' D. Compilation error

A

What happens if character 3 is entered as input? #include <iostream> using namespace std; class A { public: int i; }; int main () { int c; A obj; obj.i = 5; cin >> c; try { switch (c) { case A. throw 20; case B. throw 5.2f; case C. throw obj; default: cout<<"No exception"; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (A e) { cout << "object exception. Exception Nr. " << e.i; } catch (...) { cout << "An exception occurred."; } return 0; } A. It prints: object exception. Exception Nr. 5 B. It prints: int exception. Exception Nr. C. It prints: An exception occurred D. It prints: No exception

A

What happens when you attempt to compile and run the following code? #include <iostream> "Pass Any Exam. Any Time." - 100% Pass Guarantee! 85C++ Institute CPA Exam using namespace std; class BaseC { int *ptr; public: BaseC() { ptr = new int(10);} BaseC(int i) { ptr = new int(i); } ~BaseC() { delete ptr; } void Print() { cout << *ptr; } }; int main() { BaseC *o = new BaseC(5); o?>Print(); } A. It prints: 5 B. It prints: 10 C. It prints: 1 D. It prints: 0

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define DEF_A 0 #define DEF_B DEF_A+1 #define DEF_C DEF_B+1 int main(int argc, char *argv[]) { cout << DEF_C; return 0; } A. It prints: 2 B. It prints: 10 C. It prints: 0 D. It prints: 1

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public : void print() { cout << "A "; } }; class B { public : void print() { cout << "B "; } }; int main() { B sc[2]; A *bc = (A*)sc; for (int i=0; i<2;i++) (bc++)->print(); return 0; } A. It prints: A A B. It prints: B B C. It prints: A B D. It prints: B A

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i, j; for(i = 0, j = 1; j < 2, i < 4; i++, j++); cout << i << " " << j; return 0; } A. It prints: 4 5 B. It prints: 2 3 C. It prints: 3 2 D. It prints: 4 3

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int x,y=10; float f; f = 5.20; x=(int) f; cout << x <<", "; f=float (y); cout << f; return 0; } A. It prints: 5, 10 B. It prints: 5.2, 10 C. It prints: 5.20, 10.0 D. It prints: 5.2, 10.00

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int x=20; int *ptr; ptr = &x; cout<<*ptr; return 0; } A. It prints: 20 B. It prints: 0 C. It prints address of ptr D. It prints: 2

A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(int argc, char *argv[]) { char *s = "ABCDEF"; cout << s+2; return 0; } A. It prints: CDEF B. It prints: ABCDEF C. It prints: BCDEF D. None of these

A

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1="Hello"; string s2="World"; s1+=s2; cout << s1; return( 0 ); } A. It prints: HelloWorld B. It prints: Hello C. It prints: World D. It prints: HelWorld

A

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"Hello" , "World" }; for (int i=0; i<2; i++) { cout << s1[i]; } return( 0 ); } A. It prints: HelloWorld B. It prints: Hello C. It prints: WorldHello D. It prints: World

A

What will the variable "age" be in class B? class A { int x; protected: int y; public: int age; A () { age=5; }; }; class B : public A { string name; public: B () { name="Bob"; }; void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

A

class B : public A { string z; public: void set() { y = 4; z = "John"; } void Print() { cout << y << z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 4John B. It prints: 2John C. It prints: 23 D. It prints: 43

A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: int x; A() { x=0;} }; class B { public: int x; B() { x=1;} }; class C :public A, public B { public: int x; C(int x) { this?>x = x; A. :x = x + 1; } void Print() { cout << x << A::x << B::x; } }; int main () { C c2(1); c2.Print(); return 0; } B. It prints: 1 C. It prints: 121 D. It prints: 111 E. It prints: 2

Answer B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class SampleClass { string *s; public: SampleClass() { s = new string("Text");} SampleClass(string s) { this?>s = new string(s);} ~SampleClass() { delete s;} void Print(){ cout<<*s;} }; int main() { SampleClass *obj; obj = new SampleClass("Test"); obj?>Print(); } A. It prints: Text B. It prints: Test C. It prints: TextTest D. Garbage value.

Answer B

How could you pass arguments to functions? A. by value B. by reference C. by pointer D. by void

ABC

What is the output of this program? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"A","Z"}; string s=""; for (int i=0; i<2; i++) cout << s.append(s1[i]).insert(1,"_"); return( 0 ); } Select correct answer (single choice) A_A_Z A__Z A_A A_A__Z

A_A__Z

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Base { static int age; public: Base () {}; ~Base () {}; void setAge(int a=20) {age = a;} void Print() { cout << age;} }; int Base::age=0; int main () { Base a; a.setAge(10); a.Print(); a.setAge(); a.Print(); return 0; } A. It prints: 10 B. It prints: 20 C. It prints: 1020 D. It prints: 2010

Answer : C

What happens if characters 'w', 'o', 'r', 'l' and 'd' are entered as input? #include <iostream> #include <string> using namespace std; int main() { string s1 = "Hello"; string s2; getline( cin, s2 ); cout << s1 + s2; return( 0 ); } A. It prints: Helloworld B. It prints: Hello C. It prints: world D. Compilation error

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { protected: int y; public: int x, z; A() : x(1), y(2), z(0) {} A(int a, int b) : x(a), y(b) { z = x * y;} void Print() { cout << z; } }; class B : public A { public: int y; B() : A() {} B(int a, int b) : A(a,b) {} void Print() { cout << z; } }; int main () { A b(2,5); b.Print(); return 0; } A. It prints: 10 B. It prints: 2 C. It prints: 5 D. It prints: 1

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { protected: int y; public: int x,z; A() : x(2), y(2), z(1) { z = x + y; } A(int a, int b) : x(a), y(b) { z = x + y;} void Print() { cout << z; } }; class B : public A { public: int y; B() : A() {} B(int a, int b) : A(a,b) {} void Print() { cout << z; } }; int main () { A b; b.Print(); return 0; } A. It prints: 4 B. It prints: 0 C. It prints: 3 D. It prints: 2

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const int x=0; const int *ptr; ptr = &x; cout<<*ptr; return 0; } A. It prints: 0 B. It prints address of x C. It prints: 1 D. Compilation error

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int a=5; cout << ((a < 5) ? 9.9 : 9); } A. It prints: 9 B. It prints: 9.9 C. Compilation error D. None of these

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; for(i=10; i>-1; i/=2) { if(!i) break; } cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. Compilation error

Answer A

What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input? #include <iostream> #include <string> using namespace std; void f(); int main() { f(); return 0; } void f() { char c; c = cin.get(); cout << c; if(c != '\n') f(); } A. It prints: hello B. It prints: olleh C. It prints: h D. It prints: o

Answer A

Where does the abstract class is used? a) base class only b) derived class c) both a & b d) None of the mentioned

Answer A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class complex{ double re; double im; public: complex() : re(1),im(0.4) {} bool operator==(complex &t); }; bool complex::operator == (complex &t){ if((this?>re == t.re) && (this?>im == t.im)) return true; else return false; } int main(){ complex c1,c2; if (c1==c2) cout << "OK"; else { cout << "ERROR"; } } A. It prints: OK B. It prints: ERROR C. Compilation error D. Runtime error.

Answer A;

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i=2; switch(i) { case 1: cout<<"Hello"; break; case 2: cout<<"world"; break; case 3: printf("End"); break; } return 0; } A. It prints: Hello B. It prints: world C. It prints: End D. It prints: E

Answer B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y); float op(int x, float y); int main() { int i=1, j=2, k; float f=0.3; k = op(i, j); cout<< k << "," << op(0, f); return 0; } int op(int x, int y) { return x+y; } float op(int x, float y) "Pass Any Exam. Any Time." - 100% Pass Guarantee! 155C++ Institute CPA Exam { return x?y; } A. It prints: 3,1 B. It prints: 3,?0.3 C. It prints: 3,0 D. It prints: 0,0

Answer B

What is the output of the program? #include <iostream> #include <string> using namespace std; class First { string name; public: First() { name = "Alan"; } void Print(){ cout << name; } }; int main() { First ob1,*ob2; ob2 = new First(); ob1.Print(); ob2?>Print(); } A. Garbage value B. It prints: AlanAlan C. It prints: Alan D. It prints: Al

Answer B

What is the output of the program? #include <iostream> using namespace std; #define PRINT(i) cout<<i; int main() { int y=2, z=3; PRINT(y); PRINT(z); return 0; } A. It prints: 123 B. It prints: 23 C. It prints: 3 D. It prints: 2

Answer B

Which code, inserted at line 10, generates the output "2?1"? #include <iostream> #include <string> using namespace std; class A { protected: int y; public: int z; }; //insert code here public: void set() { y = 2; z = 3; } "Pass Any Exam. Any Time." - 100% Pass Guarantee! 156C++ Institute CPA Exam void Print() { cout << y << z; } }; int main () { B b; b.set(); b.z = ?1; b.Print(); return 0; } A. class B : private A { B. class B : public A { C. class B : protected A { D. class B {

Answer B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int f(int i); int main() { int i=0; i++; for (i=0; i<=2; i++) { cout<<f(i); } return 0; } int f(int a) { return a+a; } A. It prints: 202020 B. It prints: 012 C. It prints: 024 D. It prints: 0

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; struct Person { string name; int age; }; class First { Person *person; public: First() {person = new Person; person?>name = "John"; person?>age = 30; } void Print(){ cout<<person?>name << " "<< person?>age; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 190C++ Institute CPA Exam } }; int main() { First t; t.Print(); } A. It prints: 30 B. It prints: John C. It prints: John 30 D. It prints: John 30John 30

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: void Print(){ cout<<"from First";} }; class Second { public: void Print(){ cout<< "from Second";} }; int main() { Second t[2]; for (int i=0; i<2; i++) t[i].Print(); } A. It prints: from First B. It prints: from Firstfrom First C. It prints: from Secondfrom Second D. It prints: from Second

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i=5; switch(i) { case 1: cout<<"Hello"; break; case 2: cout<<"world"; break; case 3: break; default: cout<<"End"; } return 0; } A. It prints: Hello B. It prints: world C. It prints: End D. It prints: Helloworld

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i, j; for(i = 0; i < 2; i++) { for(j = i; j < i + 1; j++) if(j == i) continue; else break; } cout << j; return 0; } A. It prints: 0 B. It prints: 3 C. It prints: 2 D. It prints: 1

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; namespace myNamespace1 { int x = 5; int y = 10; } namespace myNamespace2 { float x = 3.14; float y = 1.5; } int main () { namespace newname = myNamespace1; using namespace newname; cout << x << " "; cout << y; return 0; } A. It prints: 5 1.5 B. It prints: 3.14 1.5 C. It prints: 5 10 D. It prints: 5

Answer C

What is the output of the program if character 3 is supplied as input? #include <iostream> using namespace std; int main () { int c; cin >> c; try { switch (c) { case 1: throw 20; case 2: throw 5.2f; case 3: throw 'a'; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (float e) { cout << "float exception. Exception Nr. " << e; } catch (...) { cout << "An exception occurred."; } return 0; } A. It prints: float exception. Exception Nr. B. It prints: int exception. Exception Nr. C. It prints: An exception occurred. D. It prints: float exception. Exception Nr

Answer C

What is the output of the program? #include <iostream> #include <string> using namespace std; struct t { int tab[2]; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 191C++ Institute CPA Exam }; class First { struct t u; public: First() { u.tab[0] = 1; u.tab[1] = 0; } void Print(){ cout << u.tab[0] << " " << u.tab[1]; } }; int main() { First t; t.Print(); } A. It prints: 2 2 B. It prints: 1 1 C. It prints: 1 0 D. It prints: 0 0

Answer C

What will be the output of the program? #include <iostream> #include <string> using namespace std; int fun(int); int main() { float k=3; k = fun(k); cout<<k; return 0; } int fun(int i) { i++; return i; } A. 3 B. 5 C. 4 D. 5

Answer C

Which of the following operations is INCORRECT? A. int i=15; B. long int k=123 C. float f=12,2; D. double d=12;

Answer C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y) { int i; i = x + y; return i; } int main() { int i=1, j=2, k, l; k = op(i, j); l = op(j, i); cout<< k << "," << l; return 0; } A. It prints: 1,2 B. It prints: ?1,1 C. It prints: 1,1 D. It prints: 3,3

Answer D

Which code, inserted at line 18, generates the output "AB" #include <iostream> using namespace std; class A{ public: void Print(){ cout<< "A";} void Print2(){ cout<< "a";} }; class B:public A{ public: void Print(){ cout<< "B";} void Print2(){ cout<< "b";} }; int main(){ B ob2; //insert code here ob2.Print(); } A. ob2?>A::Print(); B. ob2.B::Print(); C. ob2?>B::Print(); D. ob2.A::Print();

Answer D

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; A() { x=1; y=2; z=3; } }; class B : public A { public: void set() { y = 4; z = 2; } void Print() { cout << y << z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 42 B. It prints: 44 C. It prints: 22 D. It prints: 2

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A no parameters";} A(string s) { cout << "A string parameter";} A(A &a) { cout << "A object A parameter";} }; class B : public A { public: B() { cout << "B no parameters";} B(string s) { cout << "B string parameter";} }; int main () { A a1; A a2("Test"); B b1("Alan"); return 0; } A. It prints: A no parametersA string parameterA no parametersB string parameter B. It prints: A no parametersB string parameter C. It prints: B string parameter D. It prints: B no parameter

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class Base { string s; public: Base() { s="Sample text";} Base(string s) { this?>s=s; } void Print() { cout << s; } }; int main() { Base *o = new Base(); o?>Print(); } A. It prints: Sample text B. It prints: Sample C. It prints: text D. None of these

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class Second; class Base { int age; public: Base () { age=5; }; friend void set(Base &ob, Second &so); void Print() { cout << age;} }; class Second { string name; public: friend void set(Base &ob, Second &so); void Print() { cout << name;} }; void set(Base &ob, Second &so) { ob.age = 0; so.name = "Bill"; } int main () { Base a; Second b; set(a,b); a.Print(); b.Print(); return 0; } A. It prints: 0Bill B. Compilation error C. It prints: Bill0 D. None of these

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 117C++ Institute CPA Exam int main() { int i = 0; do { i++; if (i==3) break; cout<<i; } while(i < 5); return 0; } A. It prints: 12 B. It prints: 1 C. It prints: 0 D. No output

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: virtual void Print()=0; }; class B:public A { public: virtual void Print(){ cout<< "B";} }; int main() { B ob2; A *obj; obj = &ob2; obj?>Print(); } A. It prints: B B. It prints: A C. It prints: AB D. It prints: BA

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: int x; A() { x=0;} }; class B : protected A { public: int y; using A::x; B(int y) {this?>y = y;} void Print() { cout << x << y; } }; int main () { B b(5); b.Print(); return 0; } A. It prints: 05 B. It prints: 0 C. It prints: 5 D. It prints: 15

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A{ public: virtual void Print(){ cout<<"A";} }; class B:public A { public: virtual void Print(){ cout<< "B";} }; int main() { A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); } A. It prints: AB B. It prints: AA C. It prints: BA D. It prints: BB

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int f(int a, int b); int main() { float b; b = f(20,10); cout << b; return 0; } int f(int a, int b) { return a/b; } A. It prints: 2 B. It prints: 5 C. It prints: 10 D. It prints: 0

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int fun(int x) { return 2*x; } int main(){ int i; i = fun(0.5) || fun(0); cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. Compilation error

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 5; do { i??; cout<<i; } while(i >= 0); return 0; } A. It prints: 43210?1 B. It prints: ?1 C. It prints: 4321 D. It prints: 1

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { long int x,y=10; double d; d = 3.99; x=(int) d; cout << x <<", "; d=float (y); cout << d; return 0; } A. It prints: 3, 10 B. It prints: 3.99, 10 C. It prints: 4, 10.0 D. It prints: 4, 10

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 4; while(i >= 0) { cout<<i; i??; } return 0; } A. It prints:"43210" B. It prints:"3210" C. It prints: "3210?1" D. None of these

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int min(int a, int b); int main() { int min(int,int); int b; b = min(10,20); cout << b; return 0; } int min(int a, int b) { return(b); } A. It prints: 20 B. It prints: 10 C. It prints: 1020 D. It prints: 2010

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y); int main() { int i=2, j=2, k; float f=0.3; k = op(i, j); cout<< k << "," << op(1, f); return 0; } int op(int x, int y) { return x+y; } A. It prints: 4,1 B. It prints: 4,0.7 C. It prints: 4,0 D. It prints: 0,4

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; namespace myNamespace1 { int x = 5; int y = 10; } namespace myNamespace2 { float x = 3.14; float y = 1.5; } int main () { { using namespace myNamespace1; cout << x << " "; }{ using namespace myNamespace2; cout << y; } return 0; } A. It prints: 5 1.5 B. It prints: 3.14 10 C. Compilation error D. None of these

Answer: A

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void print(char *c); int main (int argc, const char * argv[]) { print("Test"); return 0; } void print(char *c) { cout<<c; } A. It prints: Test B. It prints: T C. It prints: st D. None of these

Answer: A

What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input? #include <iostream> #include <string> using namespace std; void f(); int main() "Pass Any Exam. Any Time." - 100% Pass Guarantee! 186C++ Institute CPA Exam { f(); return 0; } void f() { char c; c = cin.get(); cout << c; if(c != '\n') f(); } A. It prints: hello B. It prints: olleh C. It prints: h D. It prints: o

Answer: A

What is the output of the program? #include <iostream> using namespace std; class Base { static int age; public: Base () {}; ~Base () {}; void setAge(int a=10) {age = a;} void Print() { cout << age;} }; int Base::age=0; int main () { Base a,*b; b = new Base(); a.setAge(); b?>setAge(20); a.Print(); b?>Print(); return 0; } A. It prints: 2020 B. It prints: 1020 C. It prints: 20 D. It prints: 10

Answer: A

What is the output of the program? #include <iostream> using namespace std; class BaseC { int i; public: BaseC() { i=?1;} BaseC(int i) { i=i; } void seti(int a) { i = a; }; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 184C++ Institute CPA Exam void Print() { cout << i; } }; int main() { BaseC *o = new BaseC(); o?>seti(10); o?>Print(); } A. It prints: 10 B. It prints: ?1 C. It prints: 0 D. Compilation error

Answer: A

What will be the output of the program? #include <iostream> using namespace std; int main() { int i=0; for(; i<=5; i++) cout << i; return 0; } A. 012345 B. 0123 C. 5 D. 6

Answer: A

What will happen when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int fun(int); int main() { int *x = new int; *x=10; cout << fun(*x); return 0; } int fun(int i) { return i*i; } A. It will print: 100 B. It will print: 101 C. It will print: 10 D. It will print: 1

Answer: A

What will happen when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; string fun(string, string); int main() { string s="Hello"; cout << fun(s, " World"); return 0; } string fun(string s1, string s2) { return s1+s2; } A. It will print: Hello World B. It will print: Hello C. It will print: World D. It will print: HW

Answer: A

What will happen when you attempt to compile and run the following code? #include <iostream> using namespace std; #define A 1 int main(){ #if A cout<<"Hello"; #endif cout<<"world"; return 0; } A. It will print: Helloworld B. It will print: Hello C. It will print: world D. It will print: 0

Answer: A

Which code, inserted at line 8, generates the output "100"? #include <iostream> using namespace std; int fun(int); int main() { int *x = new int; *x=10; //insert code here return 0; } int fun(int i) { return i*i; } A. cout << fun(*x) ; B. cout << fun(10); C. cout << fun(5) ; D. cout << fun(y) ;

Answer: A,B

Which of the following structures are correct? 1: struct s1{ int x; char c; }; 2: struct s2{ float f; struct s2 *s; }; 3: struct s3{ float f; in i; } A. 1 B. 2 C. 3 D. All of these

Answer: A,B

Which of the following can be checked in a switch?case statement? A. char B. int C. enum D. double

Answer: A,B,C

Which of the following statements are correct about an array? int tab[10]; A. The array can store 10 elements. B. The expression tab[1] designates the very first element in the array. C. The expression tab[9] designates the last element in the array. D. It is necessary to initialize the array at the time of declaration.

Answer: A,C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void Print(){ cout<<"A";} }; class B:public A { public: virtual void Print(){ cout<< "B";} }; int main() { A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); } A. It prints: AB B. It prints: AA C. It prints: BA D. It prints: BB

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public : void print() { cout << "A "; } "Pass Any Exam. Any Time." - 100% Pass Guarantee! 221C++ Institute CPA Exam }; class B { public : void print() { cout << "B "; } }; int main() { B sc[2]; B *bc = (B*)sc; for (int i=0; i<2;i++) (bc++)->print(); return 0; } A. It prints: A A B. It prints: B B C. It prints: A B D. It prints: B A

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: First() { cout << "Constructor";} ~First() { cout << "Destructor";} void Print(){ cout<<"from First";} }; int main() { First FirstObject; FirstObject.Print(); } A. It prints: Constructorfrom First B. It prints: Constructorfrom FirstDestructor C. It prints: Constructorfrom FirstDestructorDestructor D. Compilation error at line 16

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: void Print(){ cout<<"from First";} }; class Second:public First { public: void Print(){ cout<< "from Second";} }; void fun(First *obj); int main() { First FirstObject; fun(&FirstObject); Second SecondObject; fun(&SecondObject); } void fun(First *obj) { obj?>Print(); } A. It prints: from First B. It prints: from Firstfrom First C. It prints: from Firstfrom Second D. It prints: from Secondfrom Second

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int *a= new int; *a=100; cout << *a; delete a; } A. It prints: 1 B. It prints: 100 C. It prints: 0 D. It prints: 10

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int *t; t = new int[2]; for (int i=0; i<2; i++) { t[i] = i; } cout << t[1]; } A. It prints: 0 B. It prints: 1 C. It prints: 10 D. It prints: ?1

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int mul (int a, int b=2) { int r; r=a*b; return (r); } int main () { cout << mul(1) << mul(2,4); return 0; } A. It prints: 2 B. It prints: 28 C. It prints: 8 D. It prints: 6

Answer: B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(int*); int main() { int *x; int i=2; x=&i; fun(x); cout<<i; return 0; } void fun(int *i) { *i = *i * *i; } A. It prints: 2 B. It prints: 4 C. It prints: 0 D. It prints: 1

Answer: B

What is the output of the program if character "1" is supplied as input? #include <iostream> using namespace std; int main () { int c; cin >> c; try { switch (c) { case 1: throw 20; case 2: throw 5.2f; case 3: throw 'a'; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (float e) { cout << "float exception. Exception Nr. " << e; } catch (...) { cout << "An exception occurred."; } return 0; } A. It prints: float exception. Exception Nr. 5.2 B. It prints: int exception. Exception Nr. 20 C. It prints: An exception occurred D. Compilation Error

Answer: B

What is the output of the program? #include <iostream> #include <string> using namespace std; union t { char c; int i; }; class First { union t u; public: First() { u.c = 'A'; } void Print(){ cout << u.c; } }; int main() { First *t = new First(); t?>Print(); } A. Garbage value B. It prints: A C. It prints: A 65 D. Compilation error

Answer: B

What is the output of the program? #include <iostream> using namespace std; #define SQR(x)(x*x) int main(int argc, char *argv[]) { int x, y=2; x = SQR(y); cout << x << ", " <<y; return 0; } A. It prints: 3, 2 B. It prints: 4, 2 C. It prints: 3, 3 D. It prints: 9, 2

Answer: B

What will be the output of the program? #include <iostream> using namespace std; int main() { const int y = 5; const x = ?10; cout<<x<<" "<<y; return 0; } A. ?10 5 B. 5 ?10 C. Compilation error D. None of these

Answer: C

If there is one, point out an error in the program #include <iostream> using namespace std; int main() { int i=1; for(;;) { cout<<i++; if(i>5) break; } return 0; } A. Error in "if" statement B. Error in "for" loop C. No error D. Error in break statement

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class complex{ double re, im; public: complex() : re(1),im(0.3) {} complex(double n) { re=n,im=n;}; complex(int m,int n) { re=m,im=n;} complex operator+(complex &t); void Print() { cout << re << " " << im; } }; complex complex::operator+ (complex &t){ complex temp; temp.re = this?>re + t.re; temp.im = this?>im + t.im; return temp; } int main(){ complex c1(1),c2(2),c3; c3 = c1 + c2; c3.Print(); } A. It prints: 1 1.5 B. It prints: 2 1.5 C. It prints: 3 3 D. It prints: 0 0

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; const int size = 3; class A { "Pass Any Exam. Any Time." - 100% Pass Guarantee! 120C++ Institute CPA Exam public: string name; A() { name = "Bob";} A(string s) { name = s;} A(A &a) { name = a.name;} }; class B : public A { public: int *tab; B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} ~B() { delete tab; } void Print() { for (int i=0; i<size; i++) cout << tab[i]; cout << name; } }; int main () { B b1("Alan"); B b2; b1.tab[0]=0; b1.Print(); b2.Print(); return 0; } A. It prints: Alan B. It prints: 111 C. It prints: 011Alan111Bob D. It prints: 0

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; void fun(int i); int main() { int i=0; i++; for (i=0; i<=5; i++) { fun(i); } return 0; } void fun(int i) "Pass Any Exam. Any Time." - 100% Pass Guarantee! 136C++ Institute CPA Exam { if (i==3) return; cout << i; } A. It prints: 05 B. It prints: 012345 C. It prints: 01245 D. It prints: 0

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void Print(){ cout<<"A";} }; class B:public A { public: virtual void Print(){ cout<< "B";} }; class C:public B { public: void Print(){ cout<< "C";} }; int main(){ A ob1; B ob2; C ob3; B *obj; obj = &ob2; obj?>Print(); obj = &ob3; obj?>Print(); } A. It prints: BB B. It prints: AA C. It prints: BC D. It prints: AB

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Base { int age; public: class C { int b; void PrintC() { cout << b; } }; Base () {age=5;}; void setAge(int a=20) {age = a;} void Print() { cout << age;} }; int main () { Base a; a.setAge(10); a.Print(); return 0; } A. It prints: 1020 B. It prints: 105 C. It prints: 10 D. It prints: 20

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class BaseC { public: int *ptr; BaseC() { ptr = new int(10);} BaseC(int i) { ptr = new int(i); } ~BaseC() { delete ptr; } }; "Pass Any Exam. Any Time." - 100% Pass Guarantee! 149C++ Institute CPA Exam void fun(BaseC x); int main() { BaseC *o = new BaseC(5); fun(*o); } void fun(BaseC x) { cout << "Hello:"<<*x.ptr; } A. It prints: Hello:50 B. It prints: Hello:10 C. It prints: Hello:5 D. Compilation error

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: virtual void Print(){ cout<<"from First";} }; class Second:public First { public: void Print(){ cout<< "from Second";} }; void fun(First *obj); int main() { First FirstObject; fun(&FirstObject); Second SecondObject; fun(&SecondObject); } void fun(First *obj) { obj?>Print(); } A. It prints: from First B. It prints: from Firstfrom First C. It prints: from Firstfrom Second D. It prints: from Secondfrom Second

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class complex{ double re; double im; public: complex() : re(0),im(0) {} complex(double x) { re=x,im=x;}; complex(double x,double y) { re=x,im=y;} void print() { cout << re << " " << im;} }; int main(){ complex c1; c1.print(); return 0; } A. It prints: 1 0 B. It prints: 1 1 C. It prints: 0 0 D. Compilation error

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 0; i++; goto lab; i++; lab: cout<<i; return 0; } A. It prints: 0 B. It prints: 34 C. It prints: 1 D. It prints: 3

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int min(int a, int b); int main() { int b=10; b = min(5,20); cout << b; return 0; } int min(int a, int b) { if (a<b) return(a); else return(b); } A. It prints: 10 B. It prints: 20 C. It prints: 5 D. It prints: 0

Answer: C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(char*); int main() { char t[4]={'0', '1', '2', '3'}; fun(&t[0]); return 0; } "Pass Any Exam. Any Time." - 100% Pass Guarantee! 219C++ Institute CPA Exam void fun(char *a) { cout << *a; } A. It prints: 01 B. It prints: 1 C. It prints: 0 D. It prints: 0123

Answer: C

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { enum state { ok, error, warning}; enum state s1, s2, s3, s4; s1 = ok; s2 = warning; s3 = error; s4 = ok; cout << s1<< s2<< s3<< s4; return 0; } A. 1234 B. compilation fails C. 0210 D. 1322

Answer: C

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { float f=?10.501; cout<<(int)f; } A. 0 B. 11 C. ?10 D. ?11

Answer: C

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { int i=10; { int i=0; cout<<i; } { int i=5; cout << i; } cout<<i; return 0; } A. 1010 B. 101010 C. 0510 D. None of these

Answer: C

What will the variable "age" be in class B? class A { int x; protected: int y; public: int age; }; class B : protected A { string name; public: void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

Answer: C

What will the variable "y" be in class B? class A { int x; protected: int y; public: int age; }; class B : protected A { string name; public: void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

Answer: C

What will variable "y" be in class B? class A { int x; protected: int y; public: int age; }; class B : public A { string name; public: void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

Answer: C

Which code, inserted at line 10, generate the output "50"? #include <iostream> using namespace std; class Base { int age; public: Base () { age=5; }; //insert code here void Print() { cout << age;} }; void setAge(Base &ob) {ob.age = 0;} int main () { Base a; a.Print(); setAge(a); a.Print(); return 0; } A. friend void setAge(Base ob); B. friend void setAge(Base *ob); C. friend void setAge(Base &ob); D. None of these

Answer: C

Which code, inserted at line 19, generates the output "23"? #include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; A() { x=1; y=2; z=3; } }; class B : public A { string z; public: int y; void set() { y = 4; z = "John"; } void Print() { //insert code here } }; int main () { B b; b.set(); b.Print(); return 0; } A. cout << y << z; B. cout << y << A::z; C. cout << A::y << A::z; D. cout << B::y << B::z;

Answer: C

Identify the incorrect option. a) 1 <= sizeof(bool) <= sizeof(long) b) sizeof(float) <= sizeof(double) <= sizeof(long double) c) sizeof(char) <= sizeof(long) <=sizeof(wchar_t) d) sizeof(N) = sizeof(signed N) = sizeof(unsigned N)

Answer: C Explanation:sizeof(char) <= sizeof(wchar_t) <= sizeof(long)

How many times will the program print "HELLO" ? #include <iostream> using namespace std; int main() { cout<<"HELLO"; main(); return 0; } A. 65536 B. 32769 C. 1 D. Till stack overflows

Answer: D

What happens when you attempt to compile and run the following code? "Pass Any Exam. Any Time." - 100% Pass Guarantee! 181C++ Institute CPA Exam #include <iostream> #include <string> using namespace std; struct Person { string name; int age; }; class First { Person *person; public: First() {person = new Person; person?>name = "John"; person?>age = 30; } void Print(){ cout<<person?>name << " "<< person?>age; } }; int main() { First t[2]; for (int i=0; i<2; i++) t[i].Print(); } A. It prints: 30 B. It prints: John C. It prints: John 31 D. It prints: John 30John 30

Answer: D

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { "Pass Any Exam. Any Time." - 100% Pass Guarantee! 179C++ Institute CPA Exam public: int age; A () { age=5; }; }; class B : private A { string name; public: B () { name="Bob"; }; void Print() { cout << name << age; } }; int main () { B b,*ob; ob = &b; ob?>age = 10; ob?>Print(); return 0; } A. It prints: Bob55 B. It prints: Bob1 C. It prints: 10 D. Compilation error

Answer: D

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { int x; protected: int y; public: int z; }; class B : private A { string name; public: void set() { x = 1; } void Print() { cout << x; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 123 B. It prints: 1 C. It prints: ?123 D. Compilation error

Answer: D

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void Print(){ cout<<"A";} }; class C:public A { public: virtual void Print()=0; }; int main() "Pass Any Exam. Any Time." - 100% Pass Guarantee! 216C++ Institute CPA Exam { C obj3; obj3?>Print(); } A. It prints: BB B. It prints: A C. It prints: AB D. Compilation error

Answer: D

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { union un { int x; char c; }; union un u1 = {10}; union un u2 = {'a'}; union un u3 = {20, 'a'}; cout<<u1.x; cout<<u2.c; cout<<u3.c; return 0; } A. It prints: 10aa B. It prints: 10a20a C. It prints: 1a D. Compilation error

Answer: D

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"H" , "t" }; string s; for (int i=0; i<2; i++) { s = s1[i]; if (i==0) s.insert(1,"ow"); else s.push_back('o'); cout << s; } return( 0 ); } A. It prints: Hoto B. It prints: Ht C. It prints: toHo D. It prints: Howto

Answer: D

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"H" , "t" }; string s; for (int i=0; i<2; i++) { s = s1[i]; s.insert(1,"ow"); cout << s; } return( 0 ); } A. It prints: How B. It prints: Ht C. It prints: Hoto D. It prints: Howtow

Answer: D

Which of the following is a correct way to define the function fun() in the program below? #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a[2][2]; fun(a); return 0; } A. void fun(int *p[2]) {} B. void fun(int *p[2][2]) {} C. void fun(int *p[][2]) {} D. void fun(int p[][2]) {}

Answer: D

What is the output of this program? #include <iostream> using namespace std; int main() { int *p; void *vp; if (vp == p); cout << "equal"; return 0; } a) equal b) no output c) compile error d) runtime error

Answer: a Explanation:The void pointer is easily converted to any other type of pointer, so these are equal. Output: equal

Pick the right option Statement 1:A definition is also a declaration. Statement 2:An identifier can be declared just once. a) Statement 1 is true, Statement 2 is false. b) Statement 2 is true, Statement 1 is false. c) Both are false. d) Both are true.

Answer: b Explanation:An identifier can be declared many times must be defined just once.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 5; cout<<"Hello World" << ++i; return 0; } A. It prints: Hello World6 B. It prints: Hello C. It prints: World D. It prints: Hello World5

Answer:A

What is the output of the program? #include <iostream> #include <string> using namespace std; class First { string name; public: First() { name = "Alan"; } void setName(string n) {this?>name = n;} void setName() {this?>name = "John";} void Print(){ cout << name; } }; int main() { First ob1,*ob2; ob2 = new First(); First *t; t = &ob1; t?>setName(); t?>Print(); t = ob2; t?>setName("Steve"); ob2?>Print(); } A. It prints: JohnSteve B. It prints: AlanAlan C. It prints: AlanSteve D. It prints: JohnAlan

Answer:A

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { char str[] = "Hello\0\World\0"; cout << str; return 0; } A. It prints: Hello B. It prints: World C. It prints: HW D. It prints: World\0World

Answer:A

What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1="World"; string s2; s2="Hello" + s1; cout << s2; return( 0 ); } A. It prints: HelloWorld B. It prints: Hello C. It prints: World D. Compilation error

Answer:A

What is not inherited from the base class? A. constructor B. destructor C. operator=() D. operator+()

Answer:A,B,C

Which of the following is a user defined data type? 1: struct person { char name[20]; int age; }; 2: int l=2; 3: enum color {red,blue, green}; D. char c; A. 1 B. 2 C. 3 D. 4

Answer:A,C

If there is one, point out an error in the program #include <iostream> using namespace std; int main(){ int c = 'a'; switch(i) { case '2': cout<<"OK"; case '1': cout<<"Error"; default: break; } return 0; } A. No Error B. Use of undeclared identifier 'i' C. Illegal use of 'continue' D. Illegal use of 'break'

Answer:B

What happens if you try to compile and run this program? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { print("Test"); return 0; } void print(int c[]) { cout<<c; } A. It prints: Test B. Compilation fails C. Program terminates abnormally D. None of these

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int main() { string s1[]= {"How" , "to" }; s1[0].swap(s1[1]); for (int i=0; i<2; i++) { cout << s1[i]; } return( 0 ); } A. It prints: Hoto B. It prints: toHow C. It prints: Ht D. It prints: to

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int fun(int x) { return 2*x; } int main(){ int i; i = fun(1) || fun(2); cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. Compilation error

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { int tab[5]={1,2,3}; for (int i=0; i<5; i++) cout <<tab[i]; return 0; } A. compilation fails B. It prints: 12300 C. It prints: 12345 D. It prints: 00000

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const char *s; char str[] = "Hello"; s = str; while(*s) { cout << *s++; } return 0; } A. It prints: el B. It prints: Hello C. It prints: H D. It prints: o

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x,y=10; float f; f = 5.90; cout << f << ", "; x=f; cout << x <<", "; f=y; cout << f; return 0; } A. It prints: 5, 5, 10.00 B. It prints: 5.9, 5, 10 C. It prints: 6, 5, 10 D. It prints: 6, 5, 10.00

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2; cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: 2 D. It prints: 0.5

Answer:B

What will happen when you attempt to compile and run the following code? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { enum state { ok, error, warning}; enum state s1, s2, s3; s1 = ok; s2 = warning; s3 = error; s4 = ok; cout << s1<< s2<< s3; return 0; } A. It will print:"123" B. compilation error C. It will print:"021" D. It will print:"132"

Answer:B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const int x=20; const int *ptr; ptr = &x; *ptr = 10; cout<<*ptr; return 0; } A. It prints: 20 B. It prints: 10 C. Compilation error at line 8 D. It prints address of ptr

Answer:C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void set(struct person*); struct person { char name[25]; int age; }; int main() { struct person e = {"Steve", 30}; set(&e); cout<< e.name << " " << e.age; return 0; } void set(struct person *p) { p?>age = p?>age + 1; } A. Error: in prototype declaration unknown struct person B. Error: in structure C. It prints: Steve 31 D. None of these

Answer:C

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

Answer:a Explanation:As the name itself implies, it have to depend on other class only.

What is the output of this program? #include <iostream> using namespace std; int main() { int age = 0; try { if (age < 0) { throw "Positive Number Required"; } cout << age; } catch(const char *Message) { cout << "Error: " << Message; } return 0; } a) 0 b) Error:Positive Number Required c) compile time error d) none of the mentioned

Answer:a Explanation:As the zero marks the beginning of the positive number, it is printed as output Output: $ g++ excep.cpp $ a.out 0

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

Answer:a Explanation:As void is not having any return value, it will not return the value to the caller

What will happen when the handler is not found for exception? a) Calls the standard library function terminate() b) raise an error c) executes the remaining block d) none of the mentioned

Answer:a Explanation:None.

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

Answer:a Explanation:As void is not having any return value, it will not return the value to the caller.

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

Answer:a Explanation:Because of the precedence the pre-increment and post increment operator, we got the output as 749736. Output: 749736

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

Answer:a Explanation:Because void pointer is used to cast the variables only, So pointer arithemetic can't be done in a void pointer.

Which of the following library is used to do vector arithmetic? a) Boost b) Time c) OpenGL d) None of the mentioned

Answer:a Explanation:Boost package has a linear algebra package that may well suits for vector arithmetic.

What would be the output of the following program (in 32-bit systems)? #include <iostream> using namespace std; int main() { cout << sizeof(char); cout << sizeof(int); cout << sizeof(float); return 0; } a) 1 4 4 b) 1 4 8 c) 1 8 8 d) none of the mentioned

Answer:a Explanation:Character is 1 byte, integer 4 bytes and float 4 bytes.

What is a comment in c++? a) comments are parts of the source code disregarded by the compiler b) comments are executed by compiler to find the meaning of the comment c) comments are executable d) none of the mentioned

Answer:a Explanation:Comments are used to add meaning to the program.

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

Answer:a Explanation:Here the condition is false on conditional operator, so the b value is assigned to c. Output: $ g++ op1.cpp $ a.out 6

If the user didn't supply the value, what value will it take? a) default value b) rise an error c) both a & b d) none of the mentioned

Answer:a Explanation:If the user didn't supply the value means, the compiler will take the given value in the argument list.

What is the output of this program? #include <iostream> using namespace std; enum test { A = 32, B, C }; int main() { cout << A << B<< C; return 0; } a) 323334 b) 323232 c) 323130 d) none of the mentioned

Answer:a Explanation:If we not assigned any value to enum variable means, then the next number to initialized number will be allocated to the variable. Output: $ g++ enum2.cpp $ a.out 323334

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

Answer:a Explanation:In a function, return type and function name are mandatory all else are just used as a choice

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

Answer:a Explanation:In function overloading, we can use any number of arguments but same function name.

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

Answer:a Explanation:In function overloading, we can use any number of arguments but same function name.

What is meant by template specialization? a) It will have certain data types to be fixed. b) It will make certain data types to be dynamic. c) Certain data types are invalid d) None of the mentioned

Answer:a Explanation:In the template specialization, it will make the template to be specific for some data types.

What is this operator called ?: ? a) conditional b) relational c) casting operator d) none of the mentioned

Answer:a Explanation:In this operator, if the condition is true means, it will return the first operator, otherwise second operator.

What is the output of this program? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; } a) 252 b) 253 c) 254 d) 262

Answer:a Explanation:In this program, We are dividing the values of a and b, printing it. Output: 252

What is the output of this program? #include <iostream> #include <algorithm> using namespace std; int main () { int myints[] = {1, 2, 3}; sort (myints, myints + 3); do { } while ( next_permutation(myints, myints + 3) ); cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n'; return 0; } a) 1 2 3 b) 3 2 1 c) 2 1 3 d) 1 3 2

Answer:a Explanation:In this program, We are doing the permutation in the do while loop and then printing last permuted value. Output: $ g++ perm1.cpp $ a.out 1 2 3

Which class is used to design the base class? a) abstract class b) derived class c) base class d) None of the mentioned

Answer:a Explanation:None.

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main (){ vector<int> a (3, 0); vector<int> b (5, 0); b = a; a = vector<int>(); cout << "Size of a " << int(a.size()) << '\n'; cout << "Size of b " << int(b.size()) << '\n'; return 0; } a) Size of a 0 Size of b 3 b) Size of a 3 Size of b 5 c) Error d)None of the mentioned

Answer:a Explanation:In this program, We are finding the size of the vector elements. Output: $ g++ vect2.cpp $ a.out Size of a 0 Size of b 3

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main () { vector<bool> mask; mask.push_back(true); mask.flip(); cout << boolalpha; for (unsigned i = 0; i < mask.size(); i++) cout << mask.at(i); return 0; } a) false b) true c) Both a & b d) None of the mentioned

Answer:a Explanation:In this program, We are fliping the vector values by using flip function. Output: $ g++ vecar1.cpp $ a.out false

What is the output of this program? #include <iostream> using namespace std; class A { public: A(int n ) { cout << n; } }; class B: public A { public: B(int n, double d) : A(n) { cout << d; } }; class C: public B { public: C(int n, double d, char ch) : B(n, d) { cout <<ch; } }; int main() { C c(5, 4.3, 'R'); return 0; } a) 54.3R b) R4.35 c) 4.3R5 d) None of the mentioned

Answer:a Explanation:In this program, We are passing the value and manipulating by using the derived class. Output: $ g++ der.cpp $ a.out 54.3R

What is the output of this program? #include <iostream> #include <string> using namespace std; template<typename T> void print_mydata(T output) { cout << output << endl; } int main() { double d = 5.5; string s("Hello World"); print_mydata( d ); print_mydata( s ); return 0; } a) 5.5 Hello World b) 5.5 c) Hello World d) none of the mentioned

Answer:a Explanation:In this program, We are passing the value to the template and printing it in the template. Output: $ g++ tem2.cpp $ a.out 5.5 Hello World

What is the output of this program? #include <iostream> using namespace std; class class0 { public: virtual ~class0(){} protected: char p; public: char getChar(); }; class class1 : public class0 { public: void printChar(); }; void class1::printChar() { cout << "True" << endl; } int main() { class1 c; c.printChar(); return 1; } a) True b) error c) no output d) runtime error

Answer:a Explanation:In this program, We are passing the values and inheriting it to the other class and printing the result. $ g++ dert.cpp $ a.out True

What is the output of this program? #include <iostream> using namespace std; template <class type> class Test { public: Test(); ~Test(); type Data(type); }; template <class type> type Test<type>::Data(type Var0) { return Var0; } template <class type> Test<type>::Test() { } template <class type> Test<type>::~Test() { } int main(void) { Test<char> Var3; cout << Var3.Data('K') << endl; return 0; } a) k b) l c) error d) runtime error

Answer:a Explanation:In this program, We are passing the values and printing it by using template inheritance. Output: $ g++ dert3.cpp $ a.out k

What is the output of this program? #include <iostream> using namespace std; void Values(int n1, int n2 = 10) { using namespace std; cout << "1st value: " << n1; cout << "2nd value: " << n2; } int main() { Values(1); Values(3, 4); return 0; } a) 1st value: 1 2nd value: 10 1st value: 3 2nd value: 4 b) 1st value: 1 2nd value: 10 1st value: 3 2nd value: 10 c) compile time error d) none of the mentioned

Answer:a Explanation:In this program, We are passing the values as by default values rules it is working. Output: 1st value: 1 2nd value: 10 1st value: 3 2nd value: 4

What is the output of this program? #include <iostream> using namespace std; class stu { protected: int rno; public: void get_no(int a) { rno = a; } void put_no(void) { } }; class test:public stu { protected: float part1,part2; public: void get_mark(float x, float y) { part1 = x; part2 = y; } void put_marks() { } }; class sports { protected: float score; public: void getscore(float s) { score = s; } void putscore(void) { } }; class result: public test, public sports { float total; public: void display(void); }; void result::display(void) { total = part1 + part2 + score; put_no(); put_marks(); putscore(); cout << "Total Score=" << total << "\n"; } int main() { result stu; stu.get_no(123); stu.get_mark(27.5, 33.0); stu.getscore(6.0); stu.display(); return 0; } a) 66.5 b) 64.5 c) 62.5 d) 60.5

Answer:a Explanation:In this program, We are passing the values by using different methods and totaling the marks to get the result. Output: $ g++ class.cpp $ a.out Total Score=66.5

What is the output of this program? #include <iostream> using namespace std; class Base { public: int m; Base(int n=0) : m(n) { cout << "Base" << endl; } }; class Derived: public Base { public: double d; Derived(double de = 0.0) : d(de) { cout << "Derived" << endl; } }; int main() { cout << "Instantiating Base" << endl; Base cBase; cout << "Instantiating Derived" << endl; Derived cDerived; return 0; } a) Instantiating Base Base Instantiating Derived Base Derived b) Instantiating Base Instantiating Derived Base Derived c) Instantiating Base Base Instantiating Derived Base d) None of the mentioned

Answer:a Explanation:In this program, We are printing the execution order of the program. Output: $ g++ der2.cpp $ a.out Instantiating Base Base Instantiating Derived Base Derived

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 16.0), c2; c2 = pow(c1, 2.0); cout << c2; return 0; } a) (-240, 128) b) (240, 128) c) (240, 120) d) None of the mentioned

Answer:a Explanation:In this program, we are finding the square of the complex number. Output: $ g++ comp.cpp $ a.out (-240,128)

What is the output of this program? #include <iostream> using namespace std; int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p + 4) = 50; for (int n = 0; n < 5; n++) cout << numbers[n] << ","; return 0; } a) 10,20,30,40,50, b) 1020304050 c) compile error d) runtime error

Answer:a Explanation:In this program, we are just assigning a value to the array and printing it and immediately dereferencing it. Output: $ g++ point4.cpp $ a.out 10,20,30,40,50,

Which design patterns benefit from the multiple inheritance? a) Adapter and observer pattern b) Code pattern c) Glue pattern d) None of the mentioned

Answer:a Explanation:None.

Which is used for manually writing lookup table? a) std:map b) std:lookup c) std:find d) None of the mentioned

Answer:a Explanation:None.

What is the output of this program? #include <iostream> using namespace std; struct Time { int hours; int minutes; int seconds; }; int toSeconds(Time now); int main() { Time t; t.hours = 5; t.minutes = 30; t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds(Time now) { return 3600 * now.hours + 60 * now.minutes + now.seconds; } a) 19845 b) 20000 c) 15000 d) 19844

Answer:a Explanation:In this program, we are just converting the given hours and minutes into seconds. Output: Total seconds:19845

What is the output of this program? #include <iostream> using namespace std; void print(int i) { cout << i; } void print(double f) { cout << f; } int main(void) { print(5); print(500.263); return 0; } a) 5500.263 b) 500.2635 c) 500.263 d) none of the mentioned

Answer:a Explanation:In this program, we are printing the values and the values will be print(5) will be printed first because of the order of the execution. Output: $ g++ over.cpp $ a.out 5500.263

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; int flue(char c,...); int main() { int x, y; x = flue('A', 1, 2, 3); y = flue('1', 1.0,1, '1', 1.0f, 1l); cout << x << y; return 0; } int flue(char c,...) { return c; } a) 6549 b) 4965 c) 6646 d) compile time error

Answer:a Explanation:In this program, we are returning the ascii value of the character and printing it. Output: 6549

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

Answer:a Explanation:In this program, we called by value so the value will not be changed, So the output is 10 Output: 10

What is the output of this program? #include <iostream> using namespace std; double division(int a, int b) { if (b == 0) { throw "Division by zero condition!"; } return (a / b); } int main () { int x = 50; int y = 2; double z = 0; try { z = division(x, y); cout << z; } catch(const char *msg) { cerr << msg; } return 0; } a) 25 b) 20 c) Division by zero condition! d) none of the mentioned

Answer:a Explanation:In this program, we resembling the division by using the exception handling. Output: $ g++ excep2.cpp $ a.out 25

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 << ' ' << d; return 0; } a) 5 6 b) 6 5 c) 6 7 d) none of the mentioned

Answer:a Explanation:It is a separtor here.In c,the value a is stored in c and in d the value b is stored in d because of the bracket. Output: 5 6

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

Answer:a Explanation:Namespace allow you to group class, objects and functions. It is used to divide the global scope into the sub-scopes.

6. What is the use of the indentation in c++? a) distinguishes between comments and code b) r distinguishes between comments and outer data c) both a and b d) none of the mentioned

Answer:a Explanation:None.

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

Answer:a Explanation:None.

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

Answer:a Explanation:None.

How the different permutations are ordered in c++? a) Compare lexicographicaly to each other elements b) By finding the highest element in the range c) By finding the lowest element in the range d) None of the mentioned

Answer:a Explanation:None.

What may be the name of the parameter that the template should take? a) same as template b) same as class c) same as function d) none of the mentioned

Answer:a Explanation:None.

What will happen when the exception is not caught in the program? a) error b) program will execute c) block of that code will not execute d) none of the mentioned

Answer:a Explanation:None.

What is the output of this program? #include <iostream> using namespace std; int n(char, int); int (*p) (char, int) = n; int main() { (*p)('d', 9); p(10, 9); return 0; } int n(char c, int i) { cout << c << i; return 0; } a) d9 9 b) d9d9 c) d9 d) compile time error

Answer:a Explanation:None. Output: d9 9

What is meant by polymorphism? a) class having many forms b) class having only single form c) class having two forms d) none of the mentioned

Answer:a Explanation:Polymirphism is literally means class having many forms.

At which time does the static_cast can be applied? a) Compile-time construct b) Runtime construct c) Both a & b d) None of the mentioned

Answer:a Explanation:Static_cast can be applied to only compile-time construct and not during run time construct.

What is the output of this program? #include <iostream> using namespace std; template <class T> inline T square(T x) { T result; result = x * x; return result; }; template <> string square<string>(string ss) { return (ss+ss); }; int main() { int i = 2, ii; string ww("A"); ii = square<int>(i); cout << i << ": " << ii; cout << square<string>(ww) << ":" << endl; } a) 2:4AA b) 2:4 c) AA d) 2:4A

Answer:a Explanation:Template specialization is used when a different and specific implementation is to be used for a specific data type. In this program, We are using integer and character. Output: $ g++ spec.cpp $ a.out 2:4AA

What is used to write multi line comment in c++? a) /* .... */ b) /$ .... $/ c) // d) none of the mentioned

Answer:a Explanation:The /* is used to write the multi line comment.

Which are done by compiler for templates? a) type-safe b) portability c) code elimination d) all of the mentioned

Answer:a Explanation:The compiler can determine at compile time whether the type associated with a template definition can perform all of the functions required by that template definition.

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

Answer:a Explanation:The default value will be used when the user value is not given, So in this case, the user value will be taken.

Which variable does equals in size with enum variable? a) int variable b) float variable c) string variable d) none of the mentioned

Answer:a Explanation:The enum variable are converted to integer and stored by compiler. So both are equal in size.

Which parameter is legal for non-type template? a) pointer to member b) object c) class d) none of the mentioned

Answer:a Explanation:The following are legal for non-type template parameters:integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.

What is the output of this program? #include <iostream> using namespace std; int g = 100; int main() { int a; { int b; b = 20; a = 35; g = 65; cout << b << a << g; } a = 50; cout << a << g; return 0; } a) 2035655065 b) 2035655035 c) 2035635065 d) none of the mentioned

Answer:a Explanation:The local values of a and g within the block are more dominant than the global values. Output: $ g++ dec1.cpp $ a.out 2035655065

Which operator is having the highest precedence? a) postfix b) unary c) shift d) equality

Answer:a Explanation:The operator which is having highest precedence is postfix and lowest is equality.

Pick out the correct statement about vector. a) vector<int> values (5) b) vector values (5) c) vector<int> (5) d) None of the mentioned

Answer:a Explanation:The syntax for declaring the vector element is vector<type> variable_name (number_of_elements);

What is the output of this program? #include <iostream> using namespace std; void addprint() { static int s = 1; s++; cout << s; } int main() { addprint(); addprint(); addprint(); return 0; } a) 234 b) 111 c) 123 d) 235

Answer:a Explanation:The variable that is declared as static has a file scope. Output: 234

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0,3.0); cout << "c1: " << c1; complex<float> c2(polar(5.0,0.75)); cout << c1 + complex<double>(c2.real(),c2.imag()); return 0; } a) c1: (4,3)(7.65844,6.40819) b) c1: (4,3)(7,6) c) both a & b d) None of the mentioned

Answer:a Explanation:We are adding the two complex numbers and printing the result. Output: $ g++ comp3.cpp $ a.out c1: (4,3)(7.65844,6.40819)

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; int add (int num, ...) { int sum = 0; va_list args; va_start (args,num); for (int i = 0; i < num; i++) { int num = va_arg (args,int); sum += num; } va_end (args); return sum; } int main (void) { int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7); cout << "The result is " << total; return 0; } a) 32 b) 23 c) 48 d) compile time error

Answer:a Explanation:We are adding these numbers by using for statement and stdarg. Output: $ g++ uka.cpp $ a.out The result is 32

What is the output of this program? #include <iostream> #include <string.h> using namespace std; int main() { struct student { int num; char name[25]; }; student stu; stu.num = 123; strcpy(stu.name, "John"); cout << stu.num << endl; cout << stu.name << endl; return 0; } a) 123 john b) john john c) compile time error d) none of the mentioned

Answer:a Explanation:We are coping the value john to the name and then we are printing the values that are in the program. Output: 123 john

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; float avg( int Count, ... ) { va_list Numbers; va_start(Numbers, Count); int Sum = 0; for (int i = 0; i < Count; ++i ) Sum += va_arg(Numbers, int); va_end(Numbers); return (Sum/Count); } int main() { float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); cout << "Average of first 10 whole numbers : " << Average; return 0; } a) 4 b) 5 c) 6 d) 7

Answer:a Explanation:We are just calculating the average of these numbers using cstdarg. Output: Average of first 10 whole numbers 4

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main(){ complex<int> i(2, 3); i = i * 6 / 3; cout << i; return 0; } a) (4, 6) b) (2, 3) c) (6, 12) d) None of the mentioned

Answer:a Explanation:We are multiplying the complex number by 2. Output: $ g++ comp2.cpp $ a.out (4,6)

What is the output of this program? #include <iostream> using namespace std; double & WeeklyHours() { double h = 46.50; double &hours = h; return hours; } int main() { double hours = WeeklyHours(); cout << "Weekly Hours: " << hours; return 0; } a) 46.5 b) 6.50 c) compile time error d) none of the mentioned

Answer:a Explanation:We are returning the value what we get as input. Output: $ g++ ret1.cpp $ a.out 46.5

What is the output of this program? #include <iostream> using namespace std; double & WeeklyHours() { double h = 46.50; double &hours = h; return hours; } int main() { double hours = WeeklyHours(); cout << "Weekly Hours: " << hours; return 0; } a) 46.5 b) 6.50 c) compile time error d) none of the mentioned View Answer

Answer:a Explanation:We are returning the value what we get as input. Output: $ g++ ret1.cpp $ a.out 46.5

What will be the output of this program? #include <iostream> using namespace std; int main() { struct ShoeType { string style; double price; }; ShoeType shoe1, shoe2; shoe1.style = "Adidas"; shoe1.price = 9.99; cout << shoe1.style << " $ "<< shoe1.price; shoe2 = shoe1; shoe2.price = shoe2.price / 9; cout << shoe2.style << " $ "<< shoe2.price; return 0; } a) Adidas $ 9.99 Adidas $ 1.11 b) Adidas $ 9.99 Adidas $ 9.11 c) Adidas $ 9.99 Adidas $ 11.11 d) none of the mentioned

Answer:a Explanation:We copied the value of shoe1 into shoe2 and divide the shoe2 value by 9, So this is the output. Output: Adidas $ 9.99 Adidas $ 1.11

What is the other name of the macro? a) scripted directive b) executed directive c) link directive d) none of the mentioned

Answer:a Explanation:When the compiler encounters a previously defined macro, it will take the result from that execution itself.

In which of the following we cannot overload the function? a) return function b) caller c) called function d) none of the mentioned

Answer:a Explanation:While overloading the return function, it will rise a error, So we can't overload the return function.

What is the Run-Time Type Information? a) Information about an object's datatype at runtime b) Information about the variables c) Information about the given block d) None of the mentioned

Answer:a Explanation:With the help of RTTI, We can get the information about the data type at the runtime.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main () { complex<double> mycomplex (20.0, 2.0); cout << imag(mycomplex) << endl; return 0; } a) 2 b) 20 c) 40 d) None of the mentioned

Answer:a Explanation:imag part will return the imaginery part of the complex number. Output: $ g++ comp5.cpp $ a.out 2

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

Answer:a Explanation:ofstream is a stream class to write on files.

What will happen when the structure is declared? a) it will not allocate any memory b) it will allocate the memory c) it will be declared and initialized d) none of the mentioned

Answer:a Explantion:While the structure is declared, it will not be initialized, So it will not allocate any memory.

Where is the derived class is derived from? a) derived b) base c) both a & b d) None of the mentioned

Answer:b Explanation:Because derived inherits functions and variables from base.

Which constructor will initialize the base class data member? a) derived class b) base class c) class d) None of the mentioned

Answer:b Explanation:Because it is having the proper data set to initialize, Otherwise it will throw a error.

What is the output of this program? #include <iostream> using namespace std; int main() { int a; a = 5 + 3 * 5; cout << a; return 0; } a) 35 b) 20 c) 25 d) 30

Answer:b Explanation:Because the * operator is having highest precedence, So it is executed first and then the + operator will be executed. Output: 20

What is the output of this program? #include <iostream> using namespace std; int main() { int i; char c; void *data; i = 2; c = 'd'; data = &i; cout << "the data points to the integer value" << data; data = &c; cout << "the data now points to the character" << data; return 0; } a) 2d b) two memory addresses c) both of the mentioned d) none of the mentioned

Answer:b Explanation:Because the data points to the address value of the variables only, So it is printing the memory address of these two variable. Output: the data points to the integer value0xbfc81824 the data now points to the character0xbfc8182f

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

Answer:b Explanation:Destructors are automatically invoked when a object goes out of scope or when a dynamically allocated object is deleted. Inheritance does not change this behavior. This is the reason a derived destructor cannot invoke its base class destructor.

What is the output of this program? #include <iostream> using namespace std; int func(void *Ptr); int main() { char *Str = "abcdefghij"; func(Str); return 0; } int func(void *Ptr) { cout << Ptr; return 0; } a) abcdefghij b) address of string "abcdefghij" c) compile time error d) runtime error

Answer:b Explanation:Even though it is a void pointer, we gets the address. Output: 0x8048714g

What is the mandatory preprosessor directive for c++? a) #define b) #include c) #undef d) none of the mentioned

Answer:b Explanation:For a c++ program to execute, we need #include.

Which is used to create a pure virtual function ? a) $ b) =0 c) & d) !

Answer:b Explanation:For making a method as pure virtual function, We have to append '=0' to the class or method.

Which symbol is used to create multiple inheritance? a) Dot b) Comma c) Dollar d) None of the mentioned

Answer:b Explanation:For using multiple inheritance, simply specify each base class (just like in single inheritance), separated by a comma.

Pick out the correct statement about permutation. a) If the function can determine the next higher permutation, Returns false. b) If the function can determine the next higher permutation, Returns true. c) If the function can't determine the next higher permutation, Returns true. d) None of the mentioned

Answer:b Explanation:If the function can determine the next higher permutation, it rearranges the elements as such and returns true.

What must be specified when we construct an object of class ostream? a) stream b) streambuf c) memory d) None of the mentioned

Answer:b Explanation:If you construct an object of class ostream, you must specify a streambuf object to the constructor.

Function overloading is also similar to which of the following? a) operator overloading b) constructor overloading c) destructor overloading d) none of the mentioned

Answer:b Explanation:In constructor overloading, we will be using the same options availed in function overloading.

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

Answer:b Explanation:In pass by reference, we can use the function to access the variable and it can modify it. Therefore we are using pass by reference.

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

Answer:b Explanation:In the call by reference, it will just copy the address of the variable to access it, so it will reduce the memory in accessing it.

The if..else statement can be replaced by which operator? a) Bitwise operator b) Conditional operator c) Multiplicative operator d) none of the mentioned

Answer:b Explanation:In the conditional operator,it will predicate the output using the given condition.

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.

Answer:b Explanation:In this expression, ptr is array not pointer.

5. What is the output of this program? #include <iostream> using namespace std; template <typename T, typename U> void squareAndPrint(T x, U y) { cout << x << x * x << endl; cout << y << " " << y * y << endl; }; int main() { int ii = 2; float jj = 2.1; squareAndPrint<int, float>(ii, jj); } a) 23 2.1 4.41 b) 24 2.1 4.41 c) 24 2.1 3.41 d) none of the mentioned

Answer:b Explanation:In this multiple templated types, We are passing two values of different types and producing the result. Output: $ g++ tem1.cpp $ a.out 24

What is the output of this program? #include <iostream> #include <exception> using namespace std; class base { virtual void dummy() {} }; class derived: public base { int a; }; int main () { try { base * pba = new derived; base * pbb = new base; derived * pd; pd = dynamic_cast<derived*>(pba); if (pd == 0) cout << "Null pointer on first type-cast" << endl; pd = dynamic_cast<derived*>(pbb); if (pd == 0) cout << "Null pointer on second type-cast" << endl; } catch (exception& e) { cout << "Exception: " << e.what(); } return 0; } a) Null pointer on first type-cast b) Null pointer on second type-cast c) Exception d) None of the mentioned

Answer:b Explanation:In this program, We apply the dynamic cast to pd. Based on the value in the pd, it produces the output. Output: $ g++ rtti.cpp $ a.out Null pointer on second type-cast

What is the output of this program? #include <iostream> using namespace std; class student { public: int rno , m1 , m2 ; void get(){ rno = 15, m1 = 10, m2 = 10; } }; class sports{ public: int sm; void getsm(){ sm = 10; } }; class statement:public student,public sports{ int tot,avg; public: void display(){ tot = (m1 + m2 + sm); avg = tot / 3; cout << tot; cout << avg; } }; int main(){ statement obj; obj.get(); obj.getsm(); obj.display(); } a) 3100 b) 3010 c) 2010 d) 1010

Answer:b Explanation:In this program, We are calculating the total and average marks of a student by using multiple inheritance. Output: $ g++ mul1.cpp $ a.out 3010

What is the output of this program? #include <iostream> using namespace std; class Base { public: virtual void print() const = 0; }; class DerivedOne : virtual public Base { public: void print() const { cout << "1"; } }; class DerivedTwo : virtual public Base { public: void print() const { cout << "2"; } }; class Multiple : public DerivedOne, DerivedTwo{ public: void print() const{ DerivedTwo::print(); } }; int main(){ Multiple both; DerivedOne one; DerivedTwo two; Base *array[ 3 ]; array[ 0 ] = &both; array[ 1 ] = &one; array[ 2 ] = &two; for ( int i = 0; i < 3; i++ ) array[ i ] -> print(); return 0; } a) 121 b) 212 c) 12 d) None of the mentioned

Answer:b Explanation:In this program, We are executing these based on the condition given in array. So it is printing as 212. Output: $ g++ abs4.cpp $ a.out 212

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector; int sum (0); myvector.push_back (100); myvector.push_back (200); myvector.push_back (300); while (!myvector.empty()) { sum += myvector.back(); myvector.pop_back(); } cout << sum << '\n'; return 0; } a) 500 b) 600 c) 700 d) Error

Answer:b Explanation:In this program, We are forming a stack and adding the elements and We are finding the total number of elements that are in stack. Output: $ g++ vect1.cpp $ a.out 600

What is the output of this program? #include <iostream> using namespace std; class BaseClass { protected: int i; public: BaseClass(int x) { i = x; } ~BaseClass() { } }; class DerivedClass: public BaseClass { int j; public: DerivedClass(int x, int y): BaseClass(y){ j = x; } ~DerivedClass() { } void show(){ cout << i << " " << j << endl; } }; int main() { DerivedClass ob(3, 4); ob.show(); return 0; } a) 3 4 b) 4 3 c) 4 d) 3

Answer:b Explanation:In this program, We are passing the values and assigning it to i and j and we are printing it. Output: $ g++ der1.cpp $ a.out 4 3

What is the output of this program? #include <iostream> using namespace std; template <class T> class A { public: A(int a): x(a) {} protected: int x; }; template <class T> class B: public A<char> { public: B(): A<char>::A(100) { cout << x * 2 << endl; } }; int main() { B<char> test; return 0; } a) 100 b) 200 c) error d) runtime error

Answer:b Explanation:In this program, We are passing the values and manipulating it by using the template inheritance. Output: $ g++ dert2.cpp $ a.out 200

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

Answer:b Explanation:In this program, We are printing the hexadecimal value of the given decimal number by using hex function. Output: $ g++ ous1.cpp $ a.out 2b

What is the output of this program? #include <iostream> #include <locale> using namespace std; int main() { locale mylocale(""); cout.imbue( mylocale ); cout << (double) 3.14159 << endl; return 0; } a) 3.14 b) 3.14159 c) Error d) None of the mentioned

Answer:b Explanation:In this program, We are using the locale and then assigning the type to the value. Output: $ g++ ous4.cpp $ a.out 3.14159

What is the output of this program? #include <iostream> using namespace std; template <class T> T max (T& a, T& b) { return (a>b?a:b); } int main () { int i = 5, j = 6, k; long l = 10, m = 5, n; k = max(i, j); n = max(l, m); cout << k << endl; cout << n << endl; return 0; } a) 6 b) 6 10 c) 5 10 d) 6 5

Answer:b Explanation:In this program, We are using the ternary operator on the template function. Output: $ g++ farg.cpp $ a.out 6 10

What is the output of this program? #include <iostream> using namespace std; class Parent { public: Parent (void) { cout << "Parent()\n"; } Parent (int i) { cout << "Parent("<< i << ")\n"; }; Parent (void) { cout << "~Parent()\n"; }; }; class Child1 : public Parent { }; class Child2 : public Parent { public: Child2 (void) { cout << "Child2()\n"; } Child2 (int i) : Parent (i) { cout << "Child2(" << i << ")\n"; } ~Child2 (void) { cout << "~Child2()\n"; } }; int main (void) { Child1 a; Child2 b; Child2 c(42); return 0; } a) Parent() Parent() Child2() Parent(42) Child2(42) ~Child2() ~Parent() ~Child2() ~Parent() ~Parent() b) error c) runtime error d) None of the mentioned

Answer:b Explanation:In this program, We got an error in overloading because we didn't invoke the destructor of parent.

How many groups of output of operation are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two groups of output operation in c++. They are formatted output and unformatted output.

How many types of comments are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of comments. They are double slash and slash stared.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 3.0); complex<float> c2(polar(5.0, 0.75)); cout << (c1 += sqrt(c1)) << endl; return 0; } a) (4.0, 3.0) b) (6.12132, 3.70711) c) (5.0, 0.75) d) None of the mentioned

Answer:b Explanation:In this program, we are adding both complex number and finding the square root of it. Output: $ g++ comp4.cpp $ a.out (6.12132,3.70711)

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; void dumplist(int, ...); int main() { dumplist(2, 4, 8); dumplist(3, 6, 9, 7); return 0; } void dumplist(int n, ...) { va_list p; int i; va_start(p, n); while (n-->0) { i = va_arg(p, int); cout << i; } va_end(p); } a) 2436 b) 48697 c) 1111111 d) compile time error

Answer:b Explanation:In this program, we are eradicating the first value by comparing using while operator. Output: $ g++ rka3.cpp $ a.out 48697

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *p; return 0; } a) 4 b) 5 c) 6 d) 7

Answer:b Explanation:In this program, we are making the pointer point to next value and printing it. $ g++ point3.cpp $ a.out 5

What is the output of this program? #include <iostream> using namespace std; int max(int a, int b ) { return ( a > b ? a : b ); } int main() { int i = 5; int j = 7; cout << max(i, j ); return 0; } a) 5 b) 7 c) either a or b d) none of the mentioned

Answer:b Explanation:In this program, we are returning the maximum value by using conditional operator. Output: $ g++ ret.cpp $ a.out 7

What is the output of this program? #include <iostream> using namespace std; int main () { cout << "Value of __LINE__ : " << __LINE__ << endl; cout << "Value of __FILE__ : " << __FILE__ << endl; cout << "Value of __DATE__ : " << __DATE__ << endl; cout << "Value of __TIME__ : " << __TIME__ << endl; return 0; } a) 5 b) Details about your file c) compile time error d) none of the mentioned

Answer:b Explanation:In this program, we are using the macros to print the information about the file. Output: Value of __LINE__ : 5 Value of __FILE__ : mac1.cpp Value of __DATE__ : Oct 10 2012 Value of __TIME__ : 22:24:37

The data elements in structure are also known as what? a) objects b) members c) datas d) none of the mentioned

Answer:b Explanation:None.

What is the default return type of a function ? a) int b) void c) float d) char

Answer:b Explanation:None.

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

Answer:b Explanation:None.

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

Answer:b Explanation:None.

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

Answer:b Explanation:None.

When our function doesn't need to return anything means what will we use/send as parameter in function? a) void b) blank space c) both a & b d) none of the mentioned

Answer:b Explanation:None.

Where can the default parameter be placed by the user? a) leftmost b) rightmost c) both a & b d) none of the mentioned

Answer:b Explanation:None.

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

Answer:b Explanation:None.

Which header file is used to declare the complex number? a) complexnum b) complex c) complexnumber d) None of the mentioned

Answer:b Explanation:None.

Which interface in the container is required for storage management? a) Memory management b) Allocater interface c) Memory interface d) None of the mentioned

Answer:b Explanation:None.

Which of the following will not return a value? a) null b) void c) empty d) free

Answer:b Explanation:None.

Which operator is used to declare the destructor? a) # b) ~ c) @ d) $

Answer:b Explanation:None.

which of the following is used to implement the c++ interfaces? a) absolute variables b) abstract classes c) constant variables d) none of the mentioned

Answer:b Explanation:None.

Where does the execution of the program starts? a) user-defined function b) main function c) void function d) none of the mentioned

Answer:b Explanation:Normally the execution of the program in c++ starts from main only.

The switch statement is also called as? a) choosing structure b) selective structure c) certain structure d) none of the mentioned

Answer:b Explanation:The switch statement is used to choose the certain code to execute, So it is also called as selective structure.

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

Answer:b Explanation:The variable is valid only in the function block as in other.

What is the output of this program? #include <iostream> using namespace std; int main() { int i; for (i = 0; i < 10; i++); { cout << i; } return 0; } a) 0123456789 b) 10 c) 012345678910 d) compile time error

Answer:b Explanation:for loop with a semicolon is called as body less for loop. It is used only for incrementing the variable values. So in this program the value is incremented and printed as 10. Output: 10

What is the output of this program? #include <iostream> using namespace std; int main() { void a = 10, b = 10; int c; c = a + b; cout << c; return 0; } a) 20 b) compile time error c) runtime error d) none of the mentioned

Answer:b Explanation:void will not accept any values to its type.

What is the output of this program? #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; } a) 11 b) 12 c) 13 d) compile time error

Answer:c Explanation:The value of a has been changed to 7, So it returns as 13. Output: 13

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

Answer:c Explanation:As it is used to execute a block of code, So we will not allocate or deallocate memory.

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << arr; return 0; } a) 4 b) 5 c) address of arr d) 7

Answer:c Explanation:As we couted to print only arr, it will print the address of the array. Output: $ g++ point2.cpp $ a.out 0xbfb1cff

What is the output of this program? #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; } a) 6 b) 24 c) segmentation fault d) compile time error

Answer:c Explanation:As we have given in the function as a+1, it will exceed the size and so it arises the segmentation fault. Output: segmentation fault

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

Answer:c Explanation:Because the cstdarg defines this header file to process the unknown number of arguments.

What is the output of this program? #include <iostream> using namespace std; int main() { /* this is comment* cout << "hello world"; return 0; } a) hello world b) hello c) compile time error d) none of the mentioned

Answer:c Explanation:Because the slash should need to be forward not backward.

What does the client module import? a) macro b) records c) interface d) none of the mentioned

Answer:c Explanation:Because they access the functions in the module using interface.

How many kinds of entities are directly parameterized in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:C++ allows us to parameterize directly three kinds of entities through templates: types, constants, and templates.

Pick the right option Statement 1:Global values are not initialized by the stream. Statement 2:Local values are implicitly initialised to 0. a) Statement 1 is true, Statement 2 is false. b) Statement 2 is true, Statement 1 is false. c) Both are false. d) Both are true.

Answer:c Explanation:Global values are implicitly initialised to 0, but local values have to be initialised by the system.

Identify the incorrect statements. int var = 10; int *ptr = &(var + 1); //statement 1 int *ptr2 = &var; //statement 2 &var = 40; //statement 3 a) Statement 1 and 2 are wrong b) Statement 2 and 3 are wrong c) Statement 1 and 3 are wrong d) All the three are wrong

Answer:c Explanation:In statement 1 lvalue is required as unary '&' operand and in statement 3 lvalue is required as left operand.

What is the output of this program? #include <iostream> using namespace std; class Base{ public: virtual void print() const = 0; }; class DerivedOne : public Base{ public: void print() const{ cout << "DerivedOne\n"; } }; class DerivedTwo : public Base{ public: void print() const{ cout << "DerivedTwo\n"; } }; class Multiple : public DerivedOne, public DerivedTwo{ public: void print() const{ DerivedTwo :: print(); } }; int main() { int i; Multiple both; DerivedOne one; DerivedTwo two; Base *array[ 3 ]; array[ 0 ] = &both; array[ 1 ] = &one; array[ 2 ] = &two; array[ i ] -> print(); return 0; } a) DerivedOne b) DerivedTwo c) Error d) None of the mentioned

Answer:c Explanation:In this program, 'Base' is an ambiguous base of 'Multiple'. So it is producing an error. And this program is a virtual base class.

What is the output of this program? #include <iostream> using namespace std; struct A { virtual void f() { cout << "Class A" << endl; } }; struct B : A { virtual void f() { cout << "Class B" << endl; } }; struct C : A { virtual void f() { cout << "Class C" << endl; } }; void f(A* arg){ B* bp = dynamic_cast<B*>(arg); C* cp = dynamic_cast<C*>(arg); if (bp) bp -> f(); else if (cp) cp -> f(); else arg -> f(); }; int main() { A aobj; C cobj; A* ap = &cobj; A* ap2 = &aobj; f(ap); f(ap2); } a) Class C b) Class A c) Both a & b d) None of the mentioned

Answer:c Explanation:In this program, We applied the dynamic casting to structure and produced the output. Output: $ g++ rtti4.cpp $ a.out Class C Class A

What is the output of this program? #include <iostream> #include <typeinfo> #include <exception> using namespace std; class base { virtual void f(){} }; class derived : public base {}; int main () { try { base* a = new base; base* b = new derived; cout << typeid(*a).name() << '\t'; cout << typeid(*b).name(); } catch (exception& e) { cout << "Exception: " << e.what() << endl; } return 0; } a) base* b) derived* c) 4base and 7derived d) None of the mentioned

Answer:c Explanation:In this program, We apply the typeid to the polymorphic class. Output: $ g++ rtti2.cpp $ a.out 4base 7derived

What is the output of this program? #include <iostream> using namespace std; class vec { public: vec(float f1, float f2) { x = f1; y = f2; } vec() { } float x; float y; }; vec addvectors(vec v1, vec v2); int main() { vec v1(3, 6); vec v2(2, -2); vec v3 = addvectors(v1, v2); cout << v3.x << ", " << v3.y << endl; } vec addvectors(vec v1, vec v2) { vec result; result.x = v1.x + v2.x; result.y = v1.y + v2.y; return result; }; a) 4, 5 b) 4, 4 c) 5, 4 d) 5, 5

Answer:c Explanation:In this program, We are adding two vectors by using standalone function and printing it. Output: $ g++ vecar.cpp $ a.out 5, 4

What is the output of this program? #include <iostream> using namespace std; class sample { public: virtual void example() = 0; }; class Ex1:public sample { public: void example() { cout << "ubuntu"; } }; class Ex2:public sample { public: void example() { cout << " is awesome"; } }; int main() { sample* arra[2]; Ex1 e1; Ex2 e2; arra[0]=&e1; arra[1]=&e2; arra[0]->example(); arra[1]->example(); } a) ubuntu b) is awesome c) ubuntu is awesome d) None of the mentioned

Answer:c Explanation:In this program, We are combining the two statements from two classes and printing it by using abstract class. Output: $ g++ abs3.cpp $ a.out ubuntu is awesome

What is the output of this program? #include <iostream> using namespace std; class MyInterface { public: virtual void Display() = 0; }; class Class1 : public MyInterface { public: void Display() { int a = 5; cout << a; } }; class Class2 : public MyInterface { public: void Display() { cout <<" 5" << endl; } }; int main() { Class1 obj1; obj1.Display(); Class2 obj2; obj2.Display(); return 0; } a) 5 b) 10 c) 5 5 d) None of the mentioned

Answer:c Explanation:In this program, We are displaying the data from the two classes by using abstract class. Output: $ g++ abs1.cpp $ a.out 5 5

What is the output of this program? #include <iostream> #include <typeinfo> using namespace std; int main () { int * a; int b; a = 0; b = 0; if (typeid(a) != typeid(b)) { cout << typeid(a).name(); cout << typeid(b).name(); } return 0; } a) Pi b) i c) Both a & b d) f

Answer:c Explanation:In this program, We are finding the typeid of the given variables. Output: $ g++ rtti1.cpp $ a.out Pii

How many ways of passing a parameter are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three ways of passing a parameter. They are pass by value,pass by reference and pass by pointer.

What is the output of this program? #include <iostream> using namespace std; class Base1 { protected: int SampleDataOne; public: Base1() { SampleDataOne = 100; } ~Base1(){ } int SampleFunctOne() { return SampleDataOne; } }; class Base2 { protected: int SampleDataTwo; public: Base2(){ SampleDataTwo = 200; } ~Base2(){ } int SampleFunctTwo(){ return SampleDataTwo; } }; class Derived1 : public Base1, public Base2{ int MyData; public: Derived1() { MyData = 300; } ~Derived1(){ } int MyFunct() { return (MyData + SampleDataOne + SampleDataTwo); } }; int main(){ Base1 SampleObjOne; Base2 SampleObjTwo; Derived1 SampleObjThree; cout << SampleObjThree.Base1 :: SampleFunctOne() << endl; cout << SampleObjThree.Base2 :: SampleFunctTwo() << endl; return 0; } a) 100 b) 200 c) Both a & b d) None of the mentioned

Answer:c Explanation:In this program, We are passing the values by using multiple inheritance and printing the derived values. Output: $ g++ mul4.cpp $ a.out 100 200

What is the output of this program? #include <iostream> using namespace std; template<typename T>class clsTemplate { public: T value; clsTemplate(T i) { this->value = i; } void test() { cout << value << endl; } }; class clsChild : public clsTemplate<char> { public: clsChild(): clsTemplate<char>( 0 ) { } clsChild(char c): clsTemplate<char>( c ) { } void test2() { test(); } }; int main() { clsTemplate <int> a( 42 ); clsChild b( 'A' ); a.test(); b.test(); return 0; } a) 42 b) A c) 42 A d) A 42

Answer:c Explanation:In this program, We are passing the values by using the template inheritance and printing it. Output: $ g++ dert.cpp $ a.out 42 A

What is the output of this program? #include <iostream> using namespace std; template <class T, int N> class mysequence { T memblock [N]; public: void setmember (int x, T value); T getmember (int x); }; template <class T, int N> void mysequence<T,N> :: setmember (int x, T value) { memblock[x] = value; } template <class T, int N> T mysequence<T,N> :: getmember (int x) { return memblock[x]; } int main () { mysequence <int, 5> myints; mysequence <double, 5> myfloats; myints.setmember (0, 100); myfloats.setmember (3, 3.1416); cout << myints.getmember(0) << '\n'; cout << myfloats.getmember(3) << '\n'; return 0; } a) 100 b) 3.1416 c) 100 3.1416 d)none of the mentioned

Answer:c Explanation:In this program, We are printing the integer in the first function and float in the second function. Output: $ g++ farg.cpp $ a.out 100 3.1416

What is the output of this program? #include <iostream> #include <vector> #include <algorithm> using namespace std; void Display(const vector<int>& vi) { for (size_t i = 0; i < vi.size(); ++i) cout << vi[i]; cout<<endl; } int main() { vector<int> vi; vi.push_back(3); vi.push_back(5); sort(vi.begin(), vi.end()); Display(vi); while(next_permutation(vi.begin(), vi.end())) Display(vi); return 0; } a) 3 5 b) 5 3 c) Both a & b d) None of the mentioned

Answer:c Explanation:In this program, We find out the permutation of two numbers by using sort. Output: $ g++ perm3.cpp $ a.out 5 3 3 5

What is the output of this program? #include <iostream> using namespace std; namespace Box1 { int a = 4; } namespace Box2 { int a = 13; } int main () { int a = 16; Box1::a; Box2::a; cout << a; return 0; } a) 4 b) 13 c) 16 d) compile time error

Answer:c Explanation:In this program, as there is lot of variable a and it is printing the value inside the block because it got the highest priority. Output: 16

What is the output of this program? #include <iostream> #include <exception> using namespace std; int main() { try { int * array1 = new int[100000000]; int * array2 = new int[100000000]; int * array3 = new int[100000000]; int * array4 = new int[100000000]; cout << "Allocated successfully"; } catch(bad_alloc&) { cout << "Error allocating the requested memory." << endl; } return 0; } a) Allocated successfully b) error allocating the requested memory c) Depends on the memory of the computer d) none of the mentioned

Answer:c Explanation:In this program, we allocating the memory to the arrays by using excetion handling and we handled the exception by standard exception. Output: $ g++ excep5.cpp $ a.out Allocated successfully

What is te output of this program? #include <iostream> using namespace std; int add(int first, int second) { return first + second + 15; } int operation(int first, int second, int (*functocall)(int, int)) { return (*functocall)(first, second); } int main() { int a; int (*plus)(int, int) = add; a = operation(15, 10, plus); cout << a; return 0; } a) 25 b) 35 c) 40 d) 45

Answer:c Explanation:In this program, we are adding two numbers with 15, So we got the output as 40. Output: 40

What is the output of this program? #include <iostream> using namespace std; main() { double a = 21.09399; float b = 10.20; int c ,d; c = (int) a; d = (int) b; cout << c <<' '<< d; return 0; } a) 20 10 b) 10 21 c) 21 10 d) none of the mentioned

Answer:c Explanation:In this program, we are casting the operator to integer, So it is printing as 21 and 10 Output: 21 10

What is the output of this program? #include <iostream> #include <string> using namespace std; string askNumber(string prompt = "Please enter a number: "); int main() { string number = askNumber(); cout << "Here is your number: " << number; return 0; } string askNumber(string prompt) { string number; cout << prompt; cin >> number; return number; } a) 5 b) 6 c) the number you entered d) compile time error

Answer:c Explanation:In this program, we are getting a number and printing it. Output: $ g++ def1.cpp $ a.out Please enter a number: 5 Here is your number:5

What is the output of this program? #include <iostream> using namespace std; void func(int a, bool flag = true) { if (flag == true ) { cout << "Flag is true. a = " << a; } else { cout << "Flag is false. a = " << a; } } int main() { func(200, false); return 0; } a) Flag is true. a = 200 b) Flag is false. a = 100 c) Flag is false. a = 200 d) Flag is true. a = 100

Answer:c Explanation:In this program, we are passing the value, as it evaluates to false, it produces the output as following. Output: Flag is false. a = 200

What is the output of this program? #include <iostream> using namespace std; void PrintSequence(int StopNum) { int Num; Num = 1; while (true) { if (Num >= StopNum) throw Num; cout << Num; Num++; } } int main(void) { try { PrintSequence(20); } catch(int ExNum) { cout << "Caught an exception with value: " << ExNum; } return 0; } a) compile time error b) prints first 19 numbers c) prints first 19 numbers and throws exception at 20 d) none of the mentioned

Answer:c Explanation:In this program, we are printing upto 19 numbers and when executing the 20, we are raising a exception. Output: $ g++ excep1.cpp $ a.out 12345678910111213141516171819Caught an exception with value: 20

What is meant by multiple inheritance? a) Deriving a base class from derived class b) Deriving a derived class from base class c) Deriving a derived class from more than one base class d) None of the mentioned

Answer:c Explanation:Multiple inheritance enables a derived class to inherit members from more than one parent.

Which of the given statements are false. 1. extern int func; 2. extern int func2(int,int); 3. int func2(int,int); 4. extern class foo; a) 3 and 4 only b) 2 and 3 only c) only 4 d) 2, 3 and 4

Answer:c Explanation:No extern are allowed for class declarations.

Which is similar to template specialization? a) template b) function overloading c) function template overloading d) None of the mentioned

Answer:c Explanation:None

Which of the following can derived class inherit? a) members b) functions c) both a & b d) None of the mentioned

Answer:c Explanation:None

How to declare a template? a) tem b) temp c) template<> d) none of the mentioned

Answer:c Explanation:None.

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 View Answer

Answer:c Explanation:None.

To which does the function pointer point to? a) variable b) constants c) function d) absolute variables

Answer:c Explanation:None.

What is similar to interface in c++ a) methods b) instance of class c) pure abstract class d) none of the mentioned

Answer:c Explanation:None.

What should be the name of constructor? a) same as object b) same as member c) same as class d) none of the mentioned

Answer:c Explanation:None.

What type of comments does c++ support? a) single line b) multi line c) single line and multi line d) none of the mentioned

Answer:c Explanation:None.

Which keyword can be used in template? a) class b) typename c) both a & b d) function

Answer:c Explanation:None.

Which of the following can be passed in function pointers? a) variables b) data types c) functions d) none of the mentioned

Answer:c Explanation:None.

Which of the following permits function overloading on c++? a) type b) number of arguments c) both of the mentioned d) none of the mentioned

Answer:c Explanation:None.

Which operator is used to signify the namespace? a) conditional operator b) ternary operator c) scope operator d) none of the mentioned

Answer:c Explanation:None.

which of the following is used to terminate the function declaration? a) : b) ) c) ; d) none of the mentioned

Answer:c Explanation:None.

Which of the following advantages we lose by using multiple inheritance? a) Dynamic binding b) Polymorphism c) Both a & b d) None of the mentioned

Answer:c Explanation:The benefit of dynamic binding and polymorphism is that they help making the code easier to extend but by multiple inheritance it makes harder to track.

Which operators are part of RTTI? a) dynamic_cast() b) typeid c) Both a & b d) None of the mentioned

Answer:c Explanation:The dynamic_cast<> operation and typeid operator in C++ are part of RTTI.

What is the output of the following program? #include <iostream> using namespace std; int main ( ) { static double i; i = 20; cout << sizeof(i); return 0; } a) 4 b) 2 c) 8 d) garbage

Answer:c Explanation:The size of the double data type is 8. 8

The declaration of structure is also called as? a) sructure creator b) structure signifier c) structure specifier d) none of the mentioned

Answer:c Explanation:The structure declaration with open and close braces and with a semicolon is also called structure specifier.

Which key word is used to check exception in the block of code? a) catch b) throw c) try d) none of the mentioned

Answer:c Explanation:The try() statement is used for exceptios in c++.

What is the output of this program? #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; } a) 11 b) 12 c) 13 d) compile time error

Answer:c Explanation:The value of a has been changed to 7, So it returns as 13. Output: 13

How many parameters are required for next_permutation? a) 1 b) 2 c) 2 or 3 d) 3

Answer:c Explanation:There are 2 or 3 needed for next_permutation. They are first, last and optional comp for comparing the elements.

How many sequence of statements are present in c++? a) 4 b) 3 c) 5 d) 6

Answer:c Explanation:There are five sequence of statements. They are Preprocessor directives,Comments,Declarations,Function Declarations,Executable statements.

How many types of constructor are there in C++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three types of constructor in C++. They are Default constructor, Parameterized constructor, Copy constructor.

What is the output of this program? #include <iostream> using namespace std; int main() { int n = 15; for ( ; ;) cout << n; return 0; } a) error b) 15 c) infinite times of printing n d) none of the mentioned

Answer:c Explanation:There is not a condition in the for loop, So it will loop continuously.

What is the header file for vector permutation? a) vector_permutation.h b) vector_perm c) <algorithm> d) vector_permutation

Answer:c Explanation:To use permutation on a vector we can use the "next_permutation" function defined in the header.

What is the output of this program? #include <iostream> using namespace std namespace space { int x = 10; } namespace space { int y = 15; } int main(int argc, char * argv[]) { space::x = space::y =5; cout << space::x << space::y; } a) 1015 b) 1510 c) 55 d) compile time error

Answer:c Explanation:We are overriding the value at the main function and so we are getting the output as 55. Output: 55

Can two functions declare variables(non static) with the same name. a) No b) Yes c) Yes, but not a very efficient way to write programs. d) No, it gives a runtime error.

Answer:c Explanation:We can declare variables with the same name in two functions because their scope lies within the function.

What is the output of this program? #include <iostream> using namespace std; int func(int m = 10, int n) { int c; c = m + n; return c; } int main() { cout << func(5); return 0; } a) 15 b) 10 c) compile time error d) none of the mentioned

Answer:c Explanation:We can't use the user argument infront of the default argument.

What is the output of this program? #include <iostream> using namespace std; void mani() void mani() { cout<<"hai"; } int main() { mani(); return 0; } a) hai b) haihai c) compile time error d) none of the mentioned

Answer:c Explanation:We have to use the semicolon to declare the function in line 3. If we did means, the program will execute.

What will be used when terminating a structure? a) : b) } c) ; d) ;;

Answer:c Explanation:While terminating a structure, a semi colon is used to end this up.

Identify the incorrect option. a) enumerators are constants b) enumerators are user defined types c) enumerators are same as macros d) enumerator values start from 0 by default

Answer:c Explanation:enumerators are used in order to create our own types whereas macros are textual substitutions

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

Answer:c Explanation:j starts with the value 10. j is then incremented to 11. Next, j is added to 100. Finally, j (still containing 11) is added to 999 which yields the result 1010. Output: 1010

What is output of the this program? #include <iostream> using namespace std; int main() { int i; enum month { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; for (i = MAR; i <= NOV; i++) cout << i; return 0; } a) 01234567891011 b) 123456789101112 c) 34567891011 d) 123456789

Answer:c Explanation:we are getting the values from march to november and printing its concern number.

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *arr + 9; return 0; } a) 12 b) 5 c) 13 d) error

Answer:c Explantion:In this program, we are adding the value 9 to the initial value of the array, So it's printing as 13. Output: $ g++ point5.cpp $ a.out 13

What is the output of this program? #include <iostream> using namespace std; void Sum(int a, int b, int & c) { a = b + c; b = a + c; c = a + b; } int main() { int x = 2, y =3; Sum(x, y, y); cout << x << " " << y; return 0; } a) 2 3 b) 6 9 c) 2 15 d) compile time error

Answer:c Explantion:We have passed three values and it will manipulate according to the given condition and yield the result as 2 15. Output: 2 15

What is the output of this program? #include <iostream> using namespace std; void func(int x) { cout << x ; } int main() { void (*n)(int); n = &func; (*n)( 2 ); n( 2 ); return 0; } a) 2 b) 20 c) 21 d) 22

Answer:d Explanation:As we are calling the function two times with the same value, So it is printing as 22. Output: $ g++ pfu.cpp $ a.out 22

Void pointer can point to which type of objects? a) int b) float c) double d) all of the mentioned

Answer:d Explanation:Because it doesn't know the type of object it is pointing to, So it can point to all objects.

What is the output of this program? #include <string> #include <iostream> using namespace std; void string_permutation( string& orig, string& perm ) { if (orig.empty()) { cout<<perm<<endl; return; } for (int i = 0; i < orig.size(); ++i) { string orig2 = orig; orig2.erase(i, 1); string perm2 = perm; perm2 += orig.at(i); string_permutation(orig2, perm2); } } int main() { string orig = "ter"; string perm; string_permutation(orig, perm); return 0; } a) ter b) ert c) ret d) Returns all the combination of ter

Answer:d Explanation:In the program, We used string permutation to find out all the combination. Output: $ g++ perm.cpp $ a.out ter tre etr ert rte ret

What is the output of this program? #include <iostream> using namespace std; class p{ protected: int width, height; public: void set_values (int a, int b){ width = a; height = b; } virtual int area (void) = 0; }; class r: public{ public: int area (void){ return (width * height); } }; class t: public p { public: int area (void){ return (width * height / 2); } }; int main () { r rect; t trgl; p * ppoly1 = &rect; p * ppoly2 = &trgl; ppoly1->set_values (4, 5); ppoly2->set_values (4, 5); cout << ppoly1 -> area() ; cout << ppoly2 -> area(); return 0; } a) 1020 b) 20 c) 10 d) 2010

Answer:d Explanation:In this program, We are calculating the area of rectangle and triangle by using abstract class. Output: $ g++ abs.cpp $ a.out 2010

What is the output of this program in the "test.txt" file? #include <fstream> using namespace std; int main () { long pos; ofstream outfile; outfile.open ("test.txt"); outfile.write ("This is an apple",16); pos = outfile.tellp(); outfile.seekp (pos - 7); outfile.write (" sam", 4); outfile.close(); return 0; } a) This is an apple b) apple c) sample d) This is a sample

Answer:d Explanation:In this program, We are changing the ap to sam by using the pos function. Output: $ g++ ous2.cpp $ a.out This is a sample

What is the output of this program? #include <iostream> #include <vector> using namespace std; class Component{ public: virtual void traverse() = 0; }; class Leaf: public Component{ int value; public: Leaf(int val){ value = val; } void traverse(){ cout << value << ' '; } }; class Composite: public Componen { vector < Component * > children; public: void add(Component *ele { children.push_back(ele); } void traverse(){ for (int i = 0; i < children.size(); i++) children[i]->traverse(); } }; int main(){ Composite containers[4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 3; j++) containers[i].add(new Leaf(i *3+j)); for (int k = 1; k < 4; k++) containers[0].add(&(containers[k])); for (int p = 0; p < 4; p++){ containers[p].traverse(); } } a) 345 b) 678 c) 901 d) None of the mentioned

Answer:d Explanation:In this program, We are choosing and printing the numbers based on the certain limit and this is a composite design pattern. Output: $ g++ cont.cpp $ a.out 0 1 2 3 4 5 6 7 8 9 10 11 3 4 5 6 7 8 9 10 11

What is the output of this program? #include <iostream> using namespace std; int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; void swap(int x, int y) { int temp = array[x]; array[x] = array[y]; array[y] = temp; return; } void printArray(int size) { int i; for (i = 0; i < size; i++) cout << array[i] << " "; cout << endl; return; } void permute(int k, int size) { int i; if (k == 0) printArray(size); else { for (i = k - 1;i >= 0;i--) { swap(i, k - 1); permute(k - 1, size); swap(i, k - 1); } } return; } int main() { permute(3, 3); return 0; } a) 0 1 2 1 0 2 b) 0 2 1 2 0 1 c) 2 1 0 1 2 0 d) All of the mentioned

Answer:d Explanation:In this program, We are finding the permutation without using the permutation function. Output: $ g++ perm2.cpp $ a.out 0 1 2 1 0 2 0 2 1 2 0 1 2 1 0 1 2 0

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main () { vector<int> first; first.assign (7,100); vector<int>::iterator it; it=first.begin()+1; int myints[] = {1776,7,4}; cout << int (first.size()) << '\n'; return 0; } a) 10 b) 9 c) 8 d) 7

Answer:d Explanation:In this program, We are finding the size of the vector elements and resizing it. Output: $ g++ vect3.cpp $ a.out 7

What is the output of this program? #include <iostream> using namespace std; template <class type> class Test { public: Test() { }; ~Test() { }; type Funct1(type Var1) { return Var1; } type Funct2(type Var2) { return Var2; } }; int main() { Test<int> Var1; Test<double> Var2; cout << Var1.Funct1(200); cout << Var2.Funct2(3.123); return 0; } a) 100 b) 200 c) 3.123 d) 2003.123

Answer:d Explanation:In this program, We are passing the value and returning it from template. Output: $ g++ farg3.cpp $ a.out 2003.123

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) 65 d) 65

Answer:d Explanation:In this program, We are printing the five spaces and then we are printing the value of 65. Output: $ g++ ous .cpp $ a.out 65

What is the output of this program? #include <iostream> using namespace std; class Base { public: Base ( ) { cout << "1" << endl; } ~Base ( ) { cout << "2" << endl; } }; class Derived : public Base { public: Derived ( ) { cout << "3" << endl; } ~Derived ( ) { cout << "4" << endl; } }; int main( ) { Derived x; } a) 1234 b) 4321 c) 1423 d) 1342

Answer:d Explanation:In this program, We are printing the order of execution of constructor and destructor in the class. Output: $ g++ dert4.cpp $ a.out 1342

What is the output of this program? #include <typeinfo> #include <iostream> using namespace std; class A { public: virtual ~A(); }; int main() { A* a = NULL; try { cout << typeid(*a).name() << endl; } catch (bad_typeid) { cout << "Object is NULL" << endl; } } a) int b) float c) double d) object is NULL

Answer:d Explanation:In this program, We are using the bad typeid() for a. So it is arising an exception. Output: $ g++ rtti3.cpp $ a.out object is NULL

What is the output of this program? #include <iostream> #include <vector> #include <iterator> #include <stddef.h> using namespace std; template<class myType> class SimpleContainer{ public: SimpleContainer(size_t xDim, size_t yDim, myType const& defaultValue) : objectData(xDim * yDim, defaultValue) , xSize(xDim) , ySize(yDim){ } myType& operator()(size_t x, size_t y{ return objectData[y * xSize + x]; } myType const& operator()(size_t x, size_t y) const{ return objectData[y * xSize + x]; } int getSize(){ return objectData.size(); } void inputEntireVector(vector<myType> inputVector){ objectData.swap(inputVector); } void printContainer(ostream& stream){ copy(objectData.begin(), objectData.end(), ostream_iterator<myType>(stream, ""/*No Space*/)); } private: vector<myType> objectData; size_t xSize; size_t ySize; }; template<class myType> inline ostream& operator<<(ostream& stream, SimpleContainer<myType>& object { object.printContainer(stream); return stream; } void sampleContainerInterfacing(); int main(){ sampleContainerInterfacing(); return 0; } void sampleContainerInterfacing(){ static int const ConsoleWidth = 80; static int const ConsoleHeight = 25; size_t width = ConsoleWidth; size_t height = ConsoleHeight; SimpleContainer<int> mySimpleContainer(width, height, 0); cout << mySimpleContainer.getSize() << endl; mySimpleContainer(0, 0) = 5; } a) 2000 b) No Space c) Error d) Depends on the compiler

Answer:d Explanation:In this program, We formed a simple container and got the size of it and printing it. Output: $ g++ cont1.cpp $ a.out 200

What is the output of this program? #include <iostream> #include <vector> using namespace std; int main (){ unsigned int i; vector<int> first; vector<int> second (4, 100); vector<int> third (second.begin(), second.end()); vector<int> fourth (third); int myints[] = {16, 2, 77, 29}; vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) ); for (vector<int> :: iterator it = fifth.begin(); it != fifth.end(); ++it) cout << ' ' << *it; return 0; } a) 16 b) 16 2 c) 16 2 77 d) 16 2 77 29

Answer:d Explanation:In this program, We got the values and printing it by using the vector and we are contructing vectors. Output: $ g++ vect.cpp $ a.out 16 2 77 29

What is the output of this program? #include <iostream> using namespace std; int gcd (int a, int b) { int temp; while (b != 0) { temp = a % b; a = b; b = temp; } return(a); } int main () { int x = 15, y = 25; cout << gcd(x, y); return(0); } a) 15 b) 25 c) 375 d) 5

Answer:d Explanation:In this program, we are finding the gcd of the number. Output: $ g++ ret5.cpp $ a.out 5

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; void fun(std::string msg, ...); int main() { fun("IndiaBIX", 1, 4, 7, 11, 0); return 0; } void fun(std::string msg, ...) { va_list ptr; int num; va_start(ptr, msg); num = va_arg(ptr, int); num = va_arg(ptr, int); cout << num; } a) 6 b) 5 c) 8 d) 4

Answer:d Explanation:In this program, we are moving the pointer to the second value and printing it. Output: 4

What is the output of this program? #include <iostream> using namespace std; int func (int a, int b) { cout << a; cout << b; return 0; } int main(void) { int(*ptr)(char, int); ptr = func; func(2, 3); ptr(2, 3); return 0; } a) 2323 b) 232 c) 23 d) compile time error

Answer:d Explanation:In this program, we can't do the casting from char to int, So it is raising an error.

How many max number of arguments can present in function in c99 compiler? a) 99 b) 90 c) 102 d) 127

Answer:d Explanation:None.

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

Answer:d Explanation:None.

What is the output of this program? #include <iostream> using namespace std; int Add(int X, int Y, int Z) { return X + Y; } double Add(double X, double Y, double Z) { return X + Y; } int main() { cout << Add(5, 6); cout << Add(5.5, 6.6); return 0; } a) 11 12.1 b) 12.1 11 c) 11 12 d) compile time error

Answer:d Explanation:None.

Which of the following is not a function of complex values? a) real b) imag c) norm d) cartesian

Answer:d Explanation:None.

Which operator is having right to left associativity in the following? a) Array subscripting b) Function call c) Addition and subtraction d) Type cast

Answer:d Explanation:None.

To which of these enumerators can be assigned? a) integer b) negative c) enumerator d) all of the mentioned

Answer:d Explanation:Since enumerators evaluate to integers, and integers can be assigned to enumerators, enumerators can be assigned to other enumerators.

What is the output of the following program? #include <iostream> using namespace std; int main() { int a = 5; float b; cout << sizeof(++a + b); cout << a; return 0; } a) 2 6 b) 4 6 c) 2 5 d) 4 5

Answer:d Explanation:The a as a integer will be converted to float while calculating the size. The value of any variable doesn't modify inside sizeof operator. Hence value of variable a will remain 5. Output: 4 5

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;};

Answer:d Explanation:The a_struct is declared as structure name and its data element is a.

Which is present in the basic interface of the allocator interface? a) Set of typedefs b) A pair of allocation functions c) allocate() d) All of the mentioned

Answer:d Explanation:The basic interface of an allocator class consists of a set of typedefs, a pair of allocation functions, allocate() and deallocate() and a pair of construction/destruction members, construct() and destroy().

Which of the things does not require instantiation? a) functions b) non virtual member function c) member class d) all of the mentioned

Answer:d Explanation:The compiler does not generate definitions for functions, non virtual member functions, class or member class because it does not require instantiation.

What does derived class does not inherit from the base class? a) constructor and destructor b) friends c) operator = () members d) all of the mentioned

Answer:d Explanation:The derived class inherit everything from the base class except the given things.

How many parameters are legal for non-type template? a) 1 b) 2 c) 3 d) 4

Answer:d Explanation:The following are legal for non-type template parameters: integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.

Which is optional in the declaration of vector? a) Type b) Name c) Vector d) Number_of_elements

Answer:d Explanation:The number of elements is optional. An empty vector means, A vector that contains zero elements.

How many types of inheritance are there in c++? a) 2 b) 3 c) 4 d) 5

Answer:d Explanation:There are five types of inheritance in c++. They are single, Multiple, Hierarchical, Multilevel, Hybrid.

How many types of modularization are there in c++? a) 4 b) 3 C) 1 d) none of the mentioned

Answer:d Explanation:There are two types of modular programming.They are interface and implementation

How many constructors can present in a class? a) 1 b) 2 c) 3 d) multiple

Answer:d Explanation:There can be multiple constructors of the same class, provided they have different signatures.

What are the things are inherited from the base class? a) Constructor and its destructor b) Operator=() members c) Friends d) All of the mentioned

Answer:d Explanation:These things can provide necessary information for the base class to make a logical decision.

What will you use if you are not intended to get a return value? a) static b) const c) volatile d) void

Answer:d Explanation:Void is used to not to return anything.

What is the output of these program? #include <iostream> using namespace std; namespace first { int x = 5; int y = 10; } namespace second { double x = 3.1416; double y = 2.7183; } int main () { using first::x; using second::y; bool a, b; a = x > y; b = first::y < second::x; cout << a << b; return 0; } a) 11 b) 01 c) 00 d) 10

Answer:d Explanation:We are inter mixing the variable and comparing it which is bigger and smaller and according to that we are printing the output. Output: 10

What is the output of this program? #include <iostream> using namespace std; void square (int *x) { *x = (*x + 1) * (*x); } int main ( ) { int num = 10; square(&num); cout << num; return 0; } a) 100 b) compile time error c) 144 d) 110

Answer:d Explanation:We have increased the x value in operand as x + 1, so it will return as 110. Output: $ g++ arg2.cpp $ a.out 110

#include <cstdlib> #include <iostream> using namespace std; float* sum(float a,float b); float* sum(float a,float b){ float *f = new float; *f = a+b; return f; } int main() { float a,b,*f; a = 1.5; b = 3.4; f = sum(a,b); cout<<*f; return 0; } A. It prints: 0 B. It prints: 4.9 C. It prints: 5 D. It prints: 4

B

#include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A no parameters";} A(string s) { cout << "A string parameter";} A(A &a) { cout << "A object A parameter";} }; class B : public A { public: B() { cout << "B no parameters";} B(string s) { cout << "B string parameter";} }; int main () { A a2("Test"); B b1("Alan"); B b2(b1); return 0; } A. It prints: A no parametersA no parametersB string parameter B. It prints: A string parameterA no parametersB string parameterA object A parameter C. It prints: A no parametersB string parameter D. It prints: A no parametersA no parameters

B

#include <iostream> #include <string> using namespace std; class A { public: int x; A() { x=0;} A(int x) { this?>x=x;} }; class B : private A { public: using A::x; B() { x=1;} B(int x) {this?>x = x;} }; int main () { B c1; B c2(?5); cout << c1.x; cout << c2.x; return 0; } A. It prints: 5 B. It prints: 1?5 C. It prints: 05 D. It prints: 0

B

#include <iostream> using namespace std; #include <iostream> using namespace std; class First{ public: void Print(){ cout<<"from First";} }; int main(){ First t[2]; for (int i=0; i<2; i++) t[i].Print(); } A. It prints: from First B. It prints: from Firstfrom First C. Compilation error D. Runtime error.

B

#include <iostream> using namespace std; class A { public: void Print(){ cout<<"A"; } }; class B:public A { public: virtual void Print(){ cout<< "B"; } }; class C:public B { public: void Print(){ cout<< "C"; } }; int main() { A ob1; B ob2; C ob3; A *obj; obj = &ob1; obj?>Print(); obj = &ob2; obj?>Print(); obj = &ob3; obj?>Print(); } A. It prints: BBB B. It prints: AAA C. It prints: ABC D. It prints: ABB

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int *i; i = new int; *i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4; cout << *i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: 2 D. It prints: 0.5

C

What happens when you attempt to compile and run the following code? #include <cstdlib> #include <iostream> using namespace std; inline float sum(float a,float b){ return a+b; } int main(){ float a,b; a = 1.5; b = 3.4; cout<<sum(a,b); return 0; } A. It prints: 0 B. It prints: 4.9 C. It prints: 5 D. It prints: 4

B

What happens when you attempt to compile and run the following code? #include <iostream> #include <cstdarg> using namespace std; int mult(int f, int s, int t); int main() { cout << mult(1,2,3); return 0; } int mult(int f, int s, int t) { int mult_res; mult_res = f*s*t; return mult_res; } A. It prints: 0 B. It prints: 6 C. It prints: 2 D. It prints: 3

B

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int f(int i, int b); int main() { int i=0; i++; for (i=0; i<=2; i++) { cout<<f(0,i); } return 0; } int f(int a, int b) { return a+b; } A. It prints: 202020 B. It prints: 012 C. It prints: 0 D. It prints: 2

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define DEF_A 0 int main(int argc, char *argv[]) { cout << DEF_A; return 0; } A. It prints: 1 B. It prints: 0 C. It prints: ?1 D. Compilation error

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void Print(){ cout<<"A";} }; class B:public A { public: void Print(){ cout<< "B";} }; int main() { A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); } A. It prints: AB B. It prints: AA C. It prints: BA D. It prints: BB

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int s(int n); int main(){ int a; a = 3; cout << s(a); return 0; } int s(int n){ if(n == 0) return 1; return s(n?1)*n; } A. It prints: 4 B. It prints: 6 C. It prints: 3 D. It prints: 0

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(int*); int main() { int i=2; fun(&i); cout<<i; return 0; } void fun(int *i) { *i = *i**i; } A. It prints: 1 B. It prints: 4 C. It prints: 10 D. It prints: 0

B

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void set(struct person*); struct person{ int age; }; int main(){ struct person e = {18}; set(&e); cout<< e.age; return 0; } void set(struct person *p){ p?>age = p?>age + 1; } A. It prints: 18 B. It prints: 19 C. It prints: 20 D. It prints: 0

B

What is the output of the program? #include <iostream> #include <string> using namespace std; int main () { string s1 = "Hello", s2 = "World"; s2 = s1 + s2; cout << s2; return 0; } A. It prints: Hello B. It prints: HelloWorld C. It prints: WorldHello D. It prints: WorldHelloWorld

B

What is the output of the program? #include <iostream> #include <string> using namespace std; struct Person { int age; }; class First { Person *person; public: First() {person = new Person; person?>age = 20; } void Print(){ cout << person?>age; } }; int main() { First t[2]; for (int i=0; i<2; i++) t[i].Print(); } A. It prints: 10 B. It prints: 2020 C. It prints: 22 D. It prints: 00

B

What will the variable "age" be in class B? class A { int x; protected: int y; public: int age; }; class B : private A { string name; public: void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

B

What will the variable "y" be in class B? class A { int x; protected: int y; public: int age; }; class B : private A { string name; public: void Print() { cout << name << age; } }; A. public B. private C. protected D. None of these

B

Which code, inserted at line 5, generates the output "ABC"? #include <iostream> using namespace std; class A { public: //insert code here }; class B:public A { public: void Print(){ cout<< "B"; } }; class C:public B { public: void Print(){ cout<< "C"; } }; int main() { A ob1; B ob2; C ob3; A *obj; obj = &ob1; obj?>Print(); obj = &ob2; obj?>Print(); obj = &ob3; obj?>Print(); } A. void Print(){ cout<<"A";} B. virtual void Print(){ cout<<"A";} C. virtual void Print(string s){ cout<<s;} D. None of these

B

Point out an error in the program. #include <iostream> using namespace std; int main() { char s1[] = "Hello"; char s2[] = "world"; char *const ptr = s1; *ptr = 'a'; ptr = s2; return 0; } A. No error B. Cannot modify a const object C. Compilation error at line 9 D. None of these

BC

Which of the following statements are correct? A. A function can be defined inside another function B. A function may have any number of return statements each returning different values. C. A function can return floating point value D. In a function two return statements should never occur.

BC

Which of the following is a logical operator? A. & B. && C. || D. !

BCD

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; if (--i==1) { cout << i; } else { cout << i-1; } return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. It prints: 2

C

#include <iostream> using namespace std; int fun(int x) { return x<<2; } int main(){ int i; i = fun(1) / 2; cout << i; return 0; } A. It prints: 0 B. It prints: 1 C. It prints: 2 D. It prints: 4

C

#include <iostream> using namespace std; int fun(int x); int main() { cout << fun(0); return 0; } int fun(int x) { if(x > 0) return fun(x-1); else return 100; } A. It prints: 0 B. It prints: 10 C. It prints: 100 D. It prints: -1

C

#include <iostream> using namespace std; int getValue(); int main(){ const int x = getValue(); cout<<x; return 0; } int getValue(){ return 5; } A. It will print 0 B. The code will not compile. C. It will print 5 D. It will print garbage value

C

#include <iostream> using namespace std; int main (int argc, const char * argv[]) { int i=10; { int i=0; cout<<i; } cout<<i; return 0; } A. 1010 B. 100 C. 010 D. None of these

C

#include <iostream> using namespace std; int x=5; static int y; int i=0; void static myFunction() { y=x++ + ++i; } int main (int argc, const char * argv[]) { x++; myFunction(); cout<<y<<" "<<x<< " " << i; } A. Compilation fails B. It prints: 5 5 0 C. It prints: 7 7 1 D. It prints: 6 5 1

C

#include <iostream> using namespace std; void fun(int &i); int main() { int i=2; fun(i); cout<<i; return 0; } void fun(int &i) { i+=2; } A. It prints: 2 B. It prints: 0 C. It prints: 4 D. It prints: 16

C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class complex{ double re, im; public: complex() : re(1),im(0.4) {} complex operator?(complex &t); void Print() { cout << re << " " << im; } }; complex complex::operator? (complex &t){ complex temp; temp.re = this?>re ? t.re; temp.im = this?>im ? t.im; return temp; } int main(){ complex c1,c2,c3; c3 = c1 ? c2; c3.Print(); } A. It prints: 1 0.4 B. It prints: 2 0.8 C. It prints: 0 0 D. It prints: 1 0.8

C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; const int size = 3; class A { public: string name; A() { name = "Bob";} A(string s) { name = s;} A(A &a) { name = a.name;} }; class B : public A { public: B() { } B(string s) : A(s) { } void Print() { cout << name; } }; int main () { B b1("Alan"); b1.Print(); return 0; } A. It prints: 111Alan B. It prints: Bob C. It prints: Alan D. It prints: 0

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: void Print(){ cout<<"from First";} }; class Second { public: void Print(){ cout<< "from Second";} }; int main() { First FirstObject; FirstObject.Print(); SecondObject.Print(); } A. It prints: from First B. It prints: from Firstfrom First C. It prints: from Firstfrom Second D. It prints: from Secondfrom Second

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Test { float i,j; }; class Add { public: int x,y; Add (int a=3, int b=3) { x=a; y=b; } int result() { return x+y;} }; int main () { Test test; Add * padd; padd = &test; cout << padd?>result(); return 0; } A. It prints: 6 B. It prints: 9 C. Compilation error D. It prints: 33

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x=2, *y; y = &x; cout << *y + x; return 0; } A. It prints: 1 B. It prints: 2 C. It prints: 4 D. It prints: 0

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i=2; switch(i){ case 1: cout<<"Hello"; case 2: cout<<"world"; case 3: cout<<"End"; } return 0; } A. It prints: Hello B. It prints: world C. It prints: worldEnd D. It prints: End

C

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y){ return x?y; } int op(int x, float y){ return x+y; } int main(){ int i=1, j=2, k, l; float f=0.23; k = op(i, j); l = op(j, f); cout<< k << "," << l; return 0; } A. It prints: ?1,?1 B. It prints: ?1,3 C. It prints: ?1,2 D. Compilation fails

C

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { int i=10; { int i=0; cout<<i; } { i=5; cout << i; } cout<<i; return 0; } A. 1010 B. 101010 C. 055 D. None of these

C

Which statement should be added in the following program to make work it correctly? using namespace std; int main (int argc, const char * argv[]) { cout<<"Hello"; } A. #include<stdio.h> B. #include<stdlib.h> C. #include <iostream> D. #include<conio.h>

C

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class Class1 { char a; protected: char b; public: char c; Class1() { a='a'; b='b'; c='c'; } }; class Class2 : public Class1 { char d; public: void set() { c = 'e'; d = 'd'; } }; int main () { Class2 a; a.set(); cout << a.c << a.d; return 0; } Select correct answer (single choice) Compilation fails It prints: cd It prints: bd It prints: ed

Compilation Fails

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const PI = 3.14; const PI2 = PI * PI; cout << PI2; return 0; } Select correct answer (single choice) It prints: 3 It prints: 9.8596 Compilation fails It prints: 3.14

Compilation Fails 'PI' does not name a type const PI = 3.14; 'PI2' does not name a type const PI2 = PI * PI; 'PI2' was not declared in this scope cout << PI2;

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class foo { int p; protected: int q; public: int r; }; class bar : public foo { public: void assign() { p = q = r = 2; } void out() { cout << q << r; } }; int main () { bar b; b.assign(); b.out(); return 0; } Select correct answer (single choice) 02 Compilation fails 22 20

Compilation Fails error: 'int foo::p' is private int p; ^ error: within this context p = q = r = 2; ^

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: const int v; A(int x) : v(x + 1) {} int get() { return ++v; } }; int main() { A a(2); cout << a.get(); return 0; } Select correct answer (single choice) Compilation fails It prints 3 It prints 2 It prints 1

Compilation Fails error: increment of read-only member 'A::v' int get() { return ++v; } ^

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> using namespace std; int main() { try { throw 3.14; } catch(double x) { x *= 2; } cout << x; return 0; } Select correct answer (single choice) It prints a non-empty string Compilation fails It prints an empty string Execution fails

Compilation error 'x' was not declared in this scope

#include <iostream> #include <string> using namespace std; int main() { string s = "a"; cout << s << "b" + "c"; return 0; } Select correct answer (single choice) It prints abc It prints ab It prints a Compilation fails

Compilation fails

#include <iostream> using namespace std; class A { public: A(float v) { A::v = v; } float v; float set(float v) { A::v += v; return v; } float get(float v) { return A::v + v; } }; int main() { A a,b(1.0); cout << a.get(b.set(1.5)); return 0; } Select correct answer (single choice) It prints 2 Compilation fails It prints 4 It prints 1

Compilation fails

#include <iostream> using namespace std; int main() { int i = 2; float f = 4.4; cout << f % float(i); return 0; } Select correct answer (single choice) It prints 0.2 It prints 0 Compilation fails It prints 2

Compilation fails

#include <iostream> using namespace std; class A { public: A(A *v) { A::v = v; } A() { A::v = 1.0; } float v; float set(float v) { A::v = v; return v; } float get(float v) { return A::v; } }; int main() { A a,*b = new A(a); cout << a->get(b->set(a->v)); return 0; } Select correct answer (single choice) It prints 2 It prints 4 It prints 1 Compilation fails

Compilation fails

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: void shout() { cout << "X"; } }; class Y : public X { public: void shout() { cout << "Y"; } }; int main() { X *x = new Y(); static_cast<Y *>(x) -> shout(); return 0; } Select correct answer (single choice) It prints Y It prints X It prints nothing Compilation fails

Compilation fails cannot convert 'Y*' to 'Z*' in assignment z = y; ^ error: comparison between distinct pointer types 'Z*' and 'Y*' lacks a cast cout << (z == y);

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> using namespace std; int main() { throw 2/4; catch(int i) { cout << i; } return 0; } Select correct answer (single choice) It prints 0 Execution fails It prints 0.5 Compilation fails

Compilation fails "expected primary expression before 'catch'"

#include <iostream> using namespace std; class X { }; class Y : public X { }; class Z : public X { }; int main() { Z *z = new Z(); Y *y = new Y(); z = y; cout << (z == y); return 0; } Select correct answer (single choice) It prints -1 It prints 0 It prints 1 Compilation fails

Compilation fails comparison between distinct pointer types 'Z*' and 'Y*' lacks a cast cout << (z == y);

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { private: int v; }; class Y : public X { Y() : v(0) {} } int main() { Y y; cout << y.v; return 0; } Select correct answer (single choice) Compilation fails It prints 1 It prints 0 It prints -1

Compilation fails error: 'int X::v' is private int v; ^ error: 'Y::Y()' is private Y() : v(0) {} error: 'int X::v' is private int v; ^

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int val = 0, *adr = &val; cout << *val; return 0; } Select correct answer (single choice) Compilation fails It prints: 1 It prints address of val It prints: 0

Compilation fails error: invalid type argument of unary '*' (have 'int') cout << *val; ^

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int val = 0, *adr = &val; cout << *val; return 0; } Select correct answer (single choice) Compilation fails It prints: 1 It prints address of val It prints: 0

Compilation fails error: invalid type argument of unary '*' (have 'int') cout << *val; ^

#include <iostream> using namespace std; class X { private: int v; }; class Y : public X { Y() : v(0) {} } int main() { Y y; cout << y.v; return 0; } Select correct answer (single choice) It prints 1 It prints -1 It prints 0 Compilation fails

Compilation fails error:'int X::v' is private error: class 'Y' does not have any field named 'v' error: within this context Y() : v(0) {}

#include <iostream> #include <string> using namespace std; int main() { int i = 2; string s = "2"; cout << s + i; return 0; } Select correct answer (single choice) It prints 2 It prints 22 It prints 4 Compilation fails

Compilation fails (Correct)

#include <iostream> using namespace std; #define FUN(arg) if(arg) cout<<"Test"; int main() { int i=1; FUN(i<3); return 0; } A. It prints: 0 B. It prints: T C. It prints: T0 D. It prints: Test

D

#include <iostream> using namespace std; class A { public: int x; A() { x=0;} }; class B : public A { public: B() { x=1;} }; class C : private B { public: C() { x=2;} }; int main () { C c1; cout << c1.x; return 0; } A. It prints: 210 B. It prints: 110 C. It prints: 010 D. Compilation error

D

#include <iostream> using namespace std; class complex{ double re; double im; public: complex() : re(0),im(0) {} complex(double x) { re=x,im=x;}; complex(double x,double y) { re=x,im=y;} void print() { cout << re << " " << im;} }; int main(){ complex c1; double i=2; c1 = i; c1.print(); return 0; } A. It prints: 0 0 B. It prints: 1 1 C. It prints: 2 0 D. It prints: 2 2

D

#include <iostream> using namespace std; int main (int argc, const char * argv[]) { int a = 30, b = 1, c = 5, i=10; i = b < a < c; cout << i; return 0; } A. compilation fails B. It prints: 10 C. It prints: 0 D. It prints: 1

D

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class BaseClass{ public: int *ptr; BaseClass(int i) { ptr = new int(i); } ~BaseClass() { delete ptr; delete ptr;} void Print() { cout << *ptr; } }; void fun(BaseClass x); int main(){ BaseClass o(10); fun(o); o.Print(); } void fun(BaseClass x) { cout << "Hello:"; } A. It prints: Hello:1 B. It prints: Hello: C. It prints: 10 D. Runtime error.

D

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x=2, *y, z=3; y = &z; cout<<x**y*x***y; return 0; } A. It prints: 36 B. It prints: 14 C. It prints: 16 D. Compilation error

D

What is the output of the program if character 2 is supplied as input? #include <iostream> using namespace std; int main () { int c; cin >> c; try{ switch (c){ case 1: throw 20; case 2: throw 5.2f; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (float e) { cout << "float exception. Exception Nr. " << e; } catch (...) { cout << "An exception occurred."; } return 0; } A. It prints: float exception. Exception Nr. B. It prints: int exception. Exception Nr. 20 C. It prints: An exception occurred D. It prints: float exception. Exception Nr. 5.2

D

Which code, inserted at line 14, generates the output "3.14 10"? #include <iostream> using namespace std; namespace myNamespace1 { int x = 5; int y = 10; } namespace myNamespace2 { float x = 3.14; float y = 1.5; } int main () { //insert code here cout << x << " " << y; return 0; } A. using myNamespace2::y; using myNamespace1::x; B. using namespace myNamespace1; C. using namespace myNamespace1; using namespace myNamespace2; D. using myNamespace1::y; using myNamespace2::x;

D

Which code, inserted at line 8, generates the output "0102020"? #include <iostream> using namespace std; class Base { static int age; public: Base () {}; ~Base () {}; //insert code here void Print() { cout << age;} }; int Base::age=0; int main () { Base a,*b; b = new Base(); a.Print(); a.setAge(10); a.Print(); b?>setAge(); a.Print(); b?>Print(); return 0; } A. void setAge(int a) {age = a;} B. void setAge() {age = 20;} C. void setAge() {age = 10;} D. void setAge(int a=20) {age = a}

D

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> using namespace std; int main() { try { throw 2./4; } catch(int i) { cout << i; } return 0; } Select correct answer (single choice) Compilation fails Execution fails It prints 0.5 It prints 0

Execution fails terminate call after throwing an instance of 'double'

What is the output of this program? #include <iostream> using namespace std; #define MIN(a,b) (((a)<(b)) ? a : b) int main () { float i, j; i = 100.1; j = 100.01; cout <<"The minimum is " << MIN(i, j) << endl; return 0; } a) 100.01 b) 100.1 c) compile time error d) none of the mentioned

Explanation: In this program, we are getting the minimum number using conditional operator. Output: The minimum value is 100.01

What is the output of this program? #include <iostream> using namespace std; class poly { protected: int width, height; public: void set_values(int a, int b) { width = a; height = b; } }; class Coutput { public: void output(int i); }; void Coutput::output(int i) { cout << i; } class rect:public poly, public Coutput { public: int area() { return(width * height); } }; class tri:public poly, public Coutput { public: int area() { return(width * height / 2); } }; int main() { rect rect; tri trgl; rect.set_values(3, 4); trgl.set_values(4, 5); rect.output(rect.area()); trgl.output(trgl.area()); return 0; } a) 1212 b) 1210 c) 1010

Explanation:In this program, We are calculating the area of rectangle and triangle by using multilevel inheritance. $ g++ class1.cpp $ a.out 1210

What is the output of this program? #include <iostream> using namespace std; class polygon { protected: int width, height; public: void set_values (int a, int b){ width = a; height = b;} }; class output1{ public: void output (int i); }; void output1::output (int i) { cout << i << endl; } class rectangle: public polygon, public output1{ public: int area (){ return (width * height); } }; class triangle: public polygon, public output1{ public: int area (){ return (width * height / 2); } }; int main () { rectangle rect; triangle trgl; rect.set_values (4, 5); trgl.set_values (4, 5); rect.output (rect.area()); trgl.output (trgl.area()); return 0; } a) 20 b) 10 c) 20 d)10

Explanation:We are using the multiple inheritance to find the area of rectangle and triangle. Output: $ g++ mul.cpp $ a.out 20 10

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int main() { bool t[] = {false, true, false & true}; string u[2] = {"false", "true"}; bool *p; p = t + 2; cout << u[*p]; return 0; } Select correct answer (single choice) It prints: true It prints: false It prints: 0 It prints: 1

False

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

If you construct an object of class ostream, you must specify a streambuf object to the constructor.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int var = -1; int static Static(int i) { static int y = 0; y += ++i; return y; } int main() { var++; Static(var++); cout << var << Static(var); } Select correct answer (single choice) It prints: 7 It prints: 11 It prints: 13 It prints: 9

It prints: 13

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> #include <stdexcept> using namespace std; class E {}; void f(int i) { E e; switch(i) { case 0 : throw e; case 1 : throw &e; } cout << 0; } int main(void) { try { f(2); } catch(E*) { cout << 1; } catch(E) { cout << 2; } return 0; } Select correct answer (single choice) It prints 2 It prints 1 Compilation fails It prints 0

It prints 0

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class Uno { public: int Int; }; class Due : public Uno { public: Due() { Int = 2;} Due(int x) { Int = x == 0 ? 2 : x - 2; } }; int main () { Due d,d2(0); cout << d.Int - d2.Int; return 0; } Select correct answer (single choice) It prints: 2 It prints: 3 It prints: 1 It prints: 0

It prints 0

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> #include <stdexcept> using namespace std; class E {}; class X { static int c; public: X() { if(c++ > 2) throw new E; } ~X() { if(c++ > 2) throw new E; } }; int X::c = 0; void f(int i) { X a,b; cout << i; } int main(void) { try { f(0); f(1); } catch(...) { cout << 1; } return 0; } Select correct answer (single choice) Compilation fails It prints 0 Execution fails It prints 01

It prints 01

#include <iostream> using namespace std; class A { public: A(A &a) { v = a.get(0.0); } A(float v) { A::v = v; } float v; float set(float v) { A::v += v; return v; } float get(float v) { return A::v + v; } }; int main() { A a(0.), b = a; cout << a.get(b.set(1.5)); return 0; } Select correct answer (single choice) Compilation fails It prints 2.5 It prints 4.5 It prints 1.5

It prints 1.5

#include <iostream> using namespace std; int main() { float *ft[3] = { new float[3], new float[3], new float[3] }, *p; for(int i = 0; i < 3; i++) { p = ft[i]; *p = p[1] = *(p + 2) = 10 * i; } cout << ft[1][1]; delete [] ft[0]; delete [] ft[1]; delete [] ft[2]; return 0; } Select correct answer (single choice) It prints 20 It prints 10 Compilation fails It prints 30

It prints 10

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { int *val; public: A() { val = new int; *val = 0; } int get() { return ++(*val); } }; int main() { A a,b = a; cout << a.get(); cout << b.get(); return 0; } Select correct answer (single choice) It prints 21 It prints 22 It prints 20 It prints 12 Compilation fails

It prints 12

#include <iostream> using namespace std; class A { public: A(A &a) { v = a.get(0.0); } A(float v) { A::v = v; } float v; float set(float v) { A::v += v; return v; } float get(float v) { return A::v + v; } }; int main() { A *a = new A(1.0), *b = new A(*a); cout << a->get(b->set(a->v)); return 0; } Select correct answer (single choice) Compilation fails It prints 4 It prints 1 It prints 2

It prints 2

#include <iostream> using namespace std; int main() { int *it[3]; for(int i = 0; i < 3; i++) { it[i] = new int [i + 1]; for(int j = 0; j < i + 1; j++) it[i][j] = 10 * i + j; } cout << it[2][2]; for(int i = 0; i < 3; i++) delete [] it[i]; return 0; } Select correct answer (single choice) It prints 11 It prints 22 It prints 33 Compilation fails

It prints 22

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: A() : val(0) {} int val; void run() { cout << val; } }; class B : public A { public: virtual void run() { cout << val + 2; } }; class C : public B { }; void Do(A *a) { B *b; C *c; if(b = static_cast<B *>(a)) b->run(); if(c = dynamic_cast<C *>(b)) c->run(); a->run(); } int main() { A *a = new C();; Do(a); return 0; } Select correct answer (single choice) It prints 221 It prints 222 It prints 220 Compilation fails

It prints 220

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: A() : val(0) {} int val; virtual void run() { cout << val; } }; class B : public A { }; class C : public B { public: void run() { cout << val + 2; } }; void Do(A *a) { B *b; C *c; if(b = dynamic_cast<B *>(a)) b->run(); if(c = dynamic_cast<C *>(a)) c->run(); a->run(); } int main() { A *a = new C();; Do(a); return 0; } Select correct answer (single choice) It prints 212 It prints 210 Compilation fails It prints 222

It prints 222

#include <iostream> using namespace std; class A { public: float v; A(float x) : v(x) {} }; class B { public: A a; float b; B(float x) : a(x + 1) { b = a.v; } }; int main() { B b(2.0); cout << b.b; return 0; } Select correct answer (single choice) It prints 3 It prints 2 Compilation fails It prints 1 Save and End Exam

It prints 3

What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; const int size = 3; class Uno { public: int n; Uno() { n = 1; } Uno(int v) { n = v;} }; class Due : public Uno { public: int *arr; Due() : Uno() { arr = new int[n]; } Due(int a) : Uno(a) { arr = new int[n]; } ~Due() { delete arr; } }; int main () { Due d(2); Due e; cout << d.n + e.n; return 0; } Select correct answer (single choice) It prints: 4 It prints: 3 It prints: 1 It prints: 2

It prints 3

#include <iostream> #include <exception> #include <stdexcept> using namespace std; class E {}; class X { public: static int c; X(int a) { c = a; } }; int X::c = 0; void f(int i) { X* t[2]; for(int j = 0; j < i; j++) t[j] = new X(i+1); for(int j = 0; j < i; j++) if(X::c++ > 2) throw new E; } int main(void) { try { f(2); } catch(...) { cout << X::c; } return 0; } Select correct answer (single choice) It prints 2 It prints 4 It prints 3 Compilation fails

It prints 4

#include <iostream> using namespace std; namespace S { int A = 1; } namespace S { int B = A + 2 ; } int main(void) { S::A = S::A + 1; { using namespace S; ++B; } cout << S::B << S::A; return 0; } Select correct answer (single choice) It prints 42 It prints 32 It prints 22 Compilation fails

It prints 42

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: A() { v = 2.5; } float v; float set(float v) { A::v += 1.0; return v; } float get(float v) { v += A::v; return v; } }; int main() { A a; cout << a.get(a.set(1.5)); return 0; } Select correct answer (single choice) Compilation fails It prints 3 It prints 5 It prints 1

It prints 5

What is the output of the program if the value of 1 is supplied as input? #include <iostream> using namespace std; class Uno { public: char Char; }; int main () { int swtch; Uno u; u.Char = '5'; cin >> swtch; try { switch (swtch) { case 3: throw 1; case 2: throw 3.f; case 1: throw u; } } catch (int e) { cout << e; } catch (Uno e) { cout << e.Char; } catch (...) { cout << "?"; } return 0; } Select correct answer (single choice) It prints: 1 It prints: 5 It prints: 3 Compilation error

It prints 5

#include <iostream> using namespace std; int main() { short s = 1; int i = 2; long l = 3; float f = 4.4; double d = 6.6; cout << s/float(i) + int(f)/i + long(d)/s; return 0; } Select correct answer (single choice) It prints 8.8 It prints 8.0 It prints 8.5 Compilation fails

It prints 8.5

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: void shout() { cout << "X"; } }; class Y : public X { }; class Z : public Y { public: void shout() { cout << "Z"; } }; int main() { Z *z = new Z(); static_cast<Y *>(z) -> shout(); return 0; } Select correct answer (single choice) It prints Y It prints X Compilation fails It prints Z

It prints X

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: void shout() { cout << "X"; } }; class Y : public X { }; class Z : public Y { public: void shout() { cout << "Z"; } }; int main() { Z *z = new Z(); static_cast<Y *>(z) -> shout(); return 0; } Select correct answer (single choice) It prints X It prints Y It prints Z Compilation fails

It prints X

What is the output of this program? #include <iostream> #include <string> using namespace std; class Uno { public: ~Uno() { cout << "X"; } }; void foo(Uno *d) { Uno e; *d = e; } int main() { Uno *u = new Uno; foo(u); delete u; return 0; } Select correct answer (single choice) It prints: XXX It prints: XX It prints: X It prints: XXXX

It prints XX

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: void shout() { cout << "X"; } }; class Y : public X { public: void shout() { cout << "Y"; } }; int main() { X *x = new Y(); static_cast<Y *>(x) -> shout(); return 0; } Select correct answer (single choice) It prints nothing It prints Y Compilation fails It prints X

It prints Y

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: virtual void shout() { cout << "X"; } }; class Y : public X { public: void shout() { cout << "Y"; } }; class Z : public Y { public: void shout() { cout << "Z"; } }; int main() { Z *z = new Z(); static_cast<Y *>(z) -> shout(); return 0; } Select correct answer (single choice) Compilation fails It prints X It prints Y It prints Z

It prints Z

#include <iostream> #include <string> using namespace std; int main() { string s1 = "aleph"; string s2 = "alpha"; string s; s1.swap(s2); s2.swap(s); s.swap(s2); cout << s2; return 0; } Select correct answer (single choice) Compilation fails It prints alpha It prints an empty string It prints aleph

It prints aleph

#include <iostream> #include <string> using namespace std; int main() { string s = "ABCDEF"; for(int i = 1; i < s.length(); i += 2) s[i - 1] = s[i] + 'a' - 'A'; cout << s; return 0; } Select correct answer (single choice) Compilation fails It prints bBdDfF (Correct) It prints BBDDFF It prints aAcCeE

It prints bBdDfF

What happens when you attempt to compile and run the following code? #include <cstdlib> #include <iostream> using namespace std; char c; char* inc(char par1, int par2) { c = par1 + par2; return &c; } int main() { int a = 'a', b = 3; char *f; f = inc(a,b); cout << *f; return 0; } Select correct answer (single choice) It prints a It prints c It prints b It prints d

It prints d

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: virtual void shout() { cout << "X"; } }; class Y : public X { public: void shout() { cout << "Y"; } }; class Z : public Y { public: void shout() { cout << "Z"; } }; int main() { Y *y = new Z(); dynamic_cast<X *>(y) -> shout(); return 0; } Select correct answer (single choice) It prints Z It prints X It prints Y Compilation fails

It prints z

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; if (--i == 1) { cout << i; } else { cout << --i; } return 0; } Select correct answer (single choice) It prints: 0 It prints: 1 It prints: --1 It prints: -1

It prints: -1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int doit(int i, int j = 0) { return (i * j); } int main () { cout << doit(doit(1,2)); return 0; } Select correct answer (single choice) It prints: 112 It prints: 0 It prints: 12 It prints: 1

It prints: 0

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int *Int = new int; *Int = 1 / 2 * 2 / 1. * 2. / 4 * 4; cout << *Int; return 0; } Select correct answer (single choice) It prints: 1 It prints: 0 It prints: 8 It prints: 2.5

It prints: 0

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { public: int v; void put(int x) { v = x; } int get(void) { return v; } }; class Y : public X { public: Y() { put(0); } void write(int x) { put(x + 1); } int read(void) { return get() - 1; } }; int main() { Y *y = new Y(); y->write(1); cout << y->read(); delete y; return 0; } Select correct answer (single choice) It prints -1 It prints 0 Compilation fails It prints 1

It prints: 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { float x = 0.9, y=-0.5; int i,j = 1; i = x + j + y; cout << i; return 0; } Select correct answer (single choice) Compilation error It prints: 1 It prints: 2 It prints: 2.4

It prints: 1

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: A() : val(0) {} int val; int inc() { ++val; return val--; } }; void Do(A *a) { a-> val = a->inc(); } int main() { A a; Do(&a); cout << a.inc(); return 0; } Select correct answer (single choice) It prints 2 It prints 0 It prints 1 Compilation fails

It prints: 2

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define A 0 #define B A+1 #define C 1-B int main() { cout << C; return 0; } Select correct answer (single choice) It prints: 1 It prints: 3 It prints: 0 It prints: 2

It prints: 2

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int a = -1, *p = &a; cout << ((p == NULL) ? 1.1 : 2.2); return 0; } Select correct answer (single choice) It prints: 2.2 It prints: 1.1 None of these Compilation error

It prints: 2.2

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; struct S { int a; char b; struct { float a; int b; } c; }; int main (int argc, const char *argv[]) { S s = { 1, 2, 3, 4 }; cout << s.c.a << s.c.b; } Select correct answer (single choice) It prints: 14 It prints: 34 It prints: 23 It prints: 12

It prints: 34

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class SupClass { public: void show(int par){ cout << par + 1;} }; class SubClass : public SupClass { public: void show(float par){ cout << par + 2;} }; int main() { SubClass o; o.show(2.0); } Select correct answer (single choice) It prints: 3 It prints: 2 It prints: 1 It prints: 4

It prints: 4

What is the output of this program? #include <iostream> using namespace std; int main() { int i = 0; for(; i < 5; i++); cout << i; return 0; } Select correct answer (single choice) It prints: 01234 It prints: 4 It prints: 012345 It prints: 5

It prints: 5

What is the output of this program? #include <iostream> #include <string> using namespace std; class Uno { public: Uno() { cout << "X"; } }; Uno foo(Uno d) { Uno e = d; return e; } int main() { Uno u; foo(u); return 0; } Select correct answer (single choice) It prints: XX It prints: X It prints: XXX It prints: XXXX

It prints: X

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X1 { public: virtual void foo() = 0; }; class X2 : public X1 { public: virtual void foo() { cout << "X2"; } }; class X3 : public X1 { public: virtual void foo() { cout << "X3"; } }; int main() { X1 *a = new X2(), *b = new X3(); b->foo(); a->foo(); return 0; } Select correct answer (single choice) It prints: X3X2 It prints: X2X3 It prints: X3X3 It prints: X2X2

It prints: X3X2

What is the output of the program given below? #include <iostream> using namespace std; int main (int argc, const char *argv[]) { float B = 32; { char B = '1'; cout << B; } { int B = 2; cout << B; } cout << B; return 0; } Select correct answer (single choice) None of these It prints: 1322 It prints: 3212 It prints: 3122

None of these output:1232

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int k = -1; class Class { public: char *adr; Class() { adr = new char[k]; } ~Class() { delete [] adr; } }; int fun(void) { Class object; return 0.5f; } int main() { fun(); return 0; } Select correct answer (single choice) Runtime error It prints: 0 It prints: 1 It prints: 0.5

Runtime Error

Generic Programming

a programming paradigm whereby fundamental requirements on types are abstracted from across concrete examples of algorithms and data structures and formalised as concepts, with generic functions implemented in terms of these concepts, typically using language genericity mechanisms as described above.

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class Sup { public: virtual void out() { cout << "p"; } }; class Sub : public Sup { public: virtual void out() { cout << "b"; } }; int main() { Sub sub; Sup *sup; sup = &sub; sup->out(); sub.out(); return 0; } Select correct answer (single choice) It prints: pb It prints: pp It prints: bp It prints: bb

bb

Which code, inserted into class C, generates the output "by"? #include <iostream> #include <string> using namespace std; class Uno { protected: char y; public: char z; }; // insert code here { public: void set() { y = 'a'; z = 'z'; } void out() { cout << ++y << --z; } }; int main () { Due b; b.set(); b.out(); return 0; } Select correct answers (multiple choice) class Due : public Uno class Due : protected Uno class Due : private Uno class Due

class Due : public Uno

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const char c = '!'; const char *p; p = &c; *p = '?'; cout << *p; return 0; } Select correct answer (single choice) It prints: ? Compilation fails It prints: ! Prints address of c

compilation fails error: assignment of read-only location '* p' *p = '?'; ^

Which code, inserted into the main function, generate the output "za"? #include <iostream> using namespace std; namespace SpaceOne { char a = 'a'; } namespace SpaceTwo { char a = 'z'; } int main () { // insert code here return 0; } Select correct answer (single choice) cout << SpaceOne::a << SpaceTwo::a; cout << SpaceTwo::a << SpaceOne::a; None of these cout << a << a;

cout << SpaceTwo::a << SpaceOne::a;

Which code, inserted into the main function, generates the output "12"? #include <iostream> #include <string> using namespace std; string fun(string s1, string s2) { return s1 + s2; } int main() { string s="1", *t = &s; //insert code here return 0; } Select correct answer (single choice) cout << fun(*t,s); cout << fun("1+2"); cout << fun("1",*t); cout << fun(*t,"2");

cout << fun(*t,"2");

What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class X { protected: int v; }; class Y : protected X { Y() : v(0) {} } int main() { Y *y = new Y(); cout << y->v; delete y; return 0; } Select correct answer (single choice) It prints 0 Compilation fails It prints 1 It prints -1

error: expected ';' after class definition } ^ error: class 'Y' does not have any field named 'v' Y() : v(0) {} ^ error: 'Y::Y()' is private Y() : v(0) {} ^ error: within this context Y *y = new Y(); ^ error: 'int X::v' is protected int v; ^ error: within this context cout << y->v; ^

What happens when you attempt to compile and run the following code? #include <iostream> #include <exception> using namespace std; int main() { try { throw exception(); } catch(exception &x) { cout << x.what(); } return 0; } Select correct answer (single choice) Compilation fails It prints a non-empty string It prints an empty string Execution fails

execution fails std::exception

What will be the output of the program? #include <iostream> #include <string> using namespace std; struct S { char *p; }; class C { S s; public: C() { s.p = new char; *s.p = 'A'; } void p() { cout << ++(*s.p); } }; int main() { C *c = new C(); c->p(); return 0; } Select correct answer (single choice) It prints: B It prints: A Compilation error Prints garbage value

it prints B

What is the output of this program? #include <iostream> #include <string> using namespace std; struct Who { string nick; }; class She { Who *who; public: She() { who = new Who; who -> nick = "Jane"; } string out (){ return who -> nick; } }; int main() { She they[2]; for(int i = 0; i < 2; i++) cout << they[i].out(); return 0; } Select correct answer (single choice) It prints: Jane Runtime error It prints: JaneJane Prints nothing

it prints: JaneJane

Which code, inserted into the main function, generate the output "a 2"? #include <iostream> using namespace std; namespace Space { char a = 'a', b = 'b'; } int a = 1, b = 2; int main () { // insert code here cout << a << " " << b; return 0; } Select correct answer (single choice) using namespace Space::a; using Space::a; None of these using namespace Space;

using Space::a;

Which code, inserted into the One class, generates the output "123"? #include <iostream> using namespace std; class One { public: //insert code here }; class Two : public One { public: void foo(){ cout << 2; } }; class Three : public Two { public: void foo(){ cout << 3; } }; int main() { One o1; Two o2; Three o3; One *o = &o1; o->foo(); o = &o2; o->foo(); o = &o3; o->foo(); } Select correct answer (single choice) None of these virtual void foo(){ cout << 1; } void foo(){ cout << 1; } static void foo(){ cout << 1; }

virtual void foo(){ cout << 1; }

What is the output of the following program? #include <iostream> #include <string> using namespace std; string fun(string t, string s = "x", int r = 1) { while(--r) s += s; t = t + s; return s; } int main() { string name = "a"; cout << fun(name); cout << name; return 0; } Select correct answer (single choice) xxxaaa xa xxxxaaaa xxaa

xa (Correct)

What is the output of this program? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *p; return 0; } a) 4 b) 5 c) 6 d) 7

Answer: 5 Explanation:In this program, we are making the pointer point to next value and printing it. 5

Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return? a) 4 b) 1 c) Implementation dependent d) Machine dependent

Answer:1 Explanation: The standard does NOT require a char to be 8-bits, but does require that sizeof(char) return 1.

What is size of generic pointer in C++ (in 32-bit platform) ? a) 2 b) 4 c) 8 d) 0

Answer:4 Explanation:Size of any type of pointer is 4 bytes in 32-bit platforms.

What will be the output of this program? #include <stdio.h> 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; }

Answer:6533 Explanation:In this program we are adding the every element of two arrays. Finally we got output as 6533.

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

Answer:ABC Explanation:We are just printing the values of first 3 values.

What constant defined in <climits> header returns the number of bits in a char? a) CHAR_SIZE b) SIZE_CHAR c) BIT_CHAR d) CHAR_BIT

Answer:CHAR_BIT Explanation: None.

The operator used for dereferencing or indirection is ____ a) * b) & c) -> d) ->>

Answer:a Explanation:None.

In C++, what is the sign of character data type by default? a) Signed b) Unsigned c) Implementation dependent d) None of these

Answer:implementation dependent Explanation: The standard does not specify if plain char is signed or unsigned. There are three distinct character types according to the standard: char, signed char and unsigned char.

What is the size of wchar_t in C++?

based on the number of bits in the system Explanation: Compiler wants to make CPU as more efficient in accessing the next value.


Related study sets

RN Comprehensive online practice 2019 A with NGN

View Set

Ch. 8 - one, Marketing Ch. 7 - one, Marketing Ch. 7 - two, Marketing Ch. 8 - two, Marketing Ch. 9 - one, Marketing Ch. 10 - one, Marketing Ch. 9 - two, Marketing Ch. 10 - two

View Set

47. Variable Interest Entities (VIEs)

View Set

Chapter 17: Taking Care of Your Vehicle and the Earth

View Set

Chapter 15: Anxiety and Obsessive-Compulsive Related Disorders

View Set

Chapter 12: Supply Chain Management in the Service Industry

View Set