Professional Documents
Culture Documents
4____________________________________________________
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
float *ft[3] = { new float[3], new float[3], new float[3] }, *p;
//10
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
int *it[3];
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
short s = 1;
int i = 2;
long l = 3;
float f = 4.4;
double d = 6.6;
//8.5
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
int i = 2;
float f = 5.8;
f = (int)f;
i = (float) i;
cout << f/i;
return 0;
}
//2.5
#include <iostream>
#include <string>
using namespace std;
int main() {
int i = 2;
string s = "2";
cout << s + i;
return 0;
}
//compilation fails
Question 6 of 10
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "a";
Question 7 of 10
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
string s1 = "1";
string s2 = "12";
//-1
Question 8 of 10
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "AB";
s.append(s).push_back(s[s.length() - 1]);
cout << s;
return 0;
}
//ABABB
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
namespace S1 {
int A = 1;
}
namespace S2 {
int A = 2 ;
}
int main(void) {
{ using namespace S1;
S2::A = A + 1;
}
{ using namespace S2;
S1::A = A + 1;
}
cout << S1::A << S2::A;
return 0;
}
//32
Question 10 of 10
What happens when you attempt to compile and run the following code?
#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;
}