Question 31
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 );
}
#include <iostream> #include <string>
using namespace std;
int main()
{
string s1="Hello";
string s2="World";
s1+=s2;
cout << s1;
return( 0 );
}
Question 32
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int fun(int x) {
return x<<2;
}
int main(){ int i;
i = fun(1) / 2;
cout << i;
return 0;
}
#include <iostream>
using namespace std;
int fun(int x) {
return x<<2;
}
int main(){ int i;
i = fun(1) / 2;
cout << i;
return 0;
}
Question 33
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();
}
#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();
}
Question 34
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;
}
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}
Question 35
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;
}
#include <iostream>
using namespace std;
int main()
{
int i = 5;
cout<<"Hello World" << ++i;
return 0;
}
