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.
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
int getValue();
int main()
{
const int x = getValue();
cout< 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
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class complex{
double re;
double im;
public:
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
What will happen when you attempt to compile and run the following code?
#include
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
Which of the following is a logical operator?
A. and
B. andand
C. ||
D. !
What happens when you attempt to compile and run the following code?
A. It prints: 1
B. It causes a compilation error
C. It prints: 0
D. It prints: My exception,
What happens when you attempt to compile and run the following code? #include
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
What happens when you attempt to compile and run the following code?
#include
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
What happens when you attempt to compile and run the following code?
#include
#include
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 andt);
void Print() { cout << re << " " << im; }
};
complex complex::operator+ (complex andt){
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
What happens when you attempt to compile and run the following code?
A. It causes a compilation error
B. It prints: Tesc failed
C. .It prints: failed
D. It prints: Tesc
What happens when you attempt to compile and run the following code?
#include
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(andFirstObject);
Second SecondObject;
fun(andSecondObject);
}
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
What happens when you attempt to compile and run the following code?
#include
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< cout< cout< return 0; } A. It prints: 10aa B. It prints: 10a20a C. It prints: 1a D. Compilation error
What is the output of the program?
#include
using namespace std;
#define PRINT(i) cout<
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
What is the output of the program?
#include
#include
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
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;