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
-
B
-
C
-
D
Reveal answer details
Close answer details
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
-
B
-
C
-
D
Reveal answer details
Close answer details
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
-
B
-
C
-
D
Reveal answer details
Close answer details
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
-
C
cout << myNamespace1::var << myNamespace2::var;
-
D
Reveal answer details
Close answer details
What happens when you attempt to compile and run the following code? #include <iostream> 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
-
B
-
C
-
D
Reveal answer details
Close answer details
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; } }; int main() { First t; t.Print(); }
-
A
-
B
-
C
-
D
It prints: John 30John 30
Reveal answer details
Close answer details
Question 7
Multiple choice
Which of the following can be checked in a switch? case statement?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 8
Multiple choice
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.
Reveal answer details
Close answer details
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 10
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 11
Single choice
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; } void fun(char *a) { cout << *a; }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 12
Single choice
What happens when you attempt to compile and run the following code? #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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 13
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 14
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 15
Single choice
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; } }; int main() {First t[2]; for (int i=0; i<2; i++) t[i].Print(); }
-
A
-
B
-
C
-
D
It prints: John 30John 30
Reveal answer details
Close answer details
Question 16
Multiple choice
Which definitions are correct?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 17
Multiple choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 18
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 19
Single choice
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]=0; } cout << t[1]; }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 20
Single choice
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]; B *bc = (B*)sc; for (int i=0; i<2;i++) (bc++)->print(); return 0; }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 21
Single choice
What happens when you attempt to compile and run the following code? 
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 22
Single choice
What happens when you attempt to compile and run the following code? 
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 23
Single choice
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
-
B
It prints: from Firstfrom First
-
C
It prints: from Firstfrom Second
-
D
It prints: from Secondfrom Second
Reveal answer details
Close answer details
Question 24
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 25
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 26
Single choice
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: void Print(){ cout<< "B";} }; int main() {A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 27
Multiple choice
How could you pass arguments to functions?
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 28
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 29
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 30
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 31
Single choice
What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input? #include <iostream> #include <string> using namespace std; int main() string s; getline( cin, s ); cout << s << " " << s.length(); return( 0 ); }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 32
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 33
Single choice
What happens when you attempt to compile and run the following code? 
-
A
-
B
It causes a compilation error
-
C
-
D
Reveal answer details
Close answer details
Question 34
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 35
Single choice
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 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
Reveal answer details
Close answer details
Question 36
Single choice
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
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 37
Multiple choice
Which code lines inserted independently instead of the comment will make the following program work correctly? (Choose three.) 
-
A
int main (int argc, char *argv[])
-
B
int main (int c, char *v[])
-
C
-
D
Reveal answer details
Close answer details
Question 38
Single choice
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i = 0; do { i++; if (i==3) break; cout<<i; } while(i < 5); return 0; }
-
A
-
B
-
C
-
D
Reveal answer details
Close answer details
Question 39
Single choice
What is the output of the program? #include <iostream> #include <string> using namespace std; struct t { int tab[2]; }; 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
-
B
-
C
-
D
Reveal answer details
Close answer details
|