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
B. #include
C. #include
D. #include
Which code, inserted at line 8, generates the output "0102020"?
#include
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();
B. setAge(10);
C. Print(); b?>setAge();
D. Print(); b?>Print(); return 0; }
E. void setAge(int a) {age = a;}
F. void setAge() {age = 20;}
G. void setAge() {age = 10;}
H. void setAge(int a=20) {age = a;}
What happens when you attempt to compile and run the following code?
#include
#include
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; }
B. It prints: ?3
C. It prints: 2
D. It prints: 6
E. It prints: 5
Point out an error in the program.
#include
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
What happens when you attempt to compile and run the following code?
#include
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
What will be the output of the program?
#include
using namespace std;
int main()
{
int i=0;
for(; i<=5; i++)
cout << i;
return 0;
}
A. 012345
B. 0123
C. 5
D. 6
What is not inherited from the base class?
A. constructor
B. destructor
C. operator=()
D. operator+()
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
What happens when you attempt to compile and run the following code? #include
#include
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<
}
};
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
What happens 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++;
}
return 0;
}
A. It prints: el
B. It prints: Hello
C. It prints: H
D. It prints: o