#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "0123456789";
cout << s.substr(3,7).substr(2).substr();
return 0;
}
/*
Select correct answer (single choice)
It prints an empty string
It prints 34567
Compilation fails
It prints 56789
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1 = "aleph";
string s2 = "alpha";
string s;
s1.swap(s2);
s2.swap(s);
s.swap(s2);
cout << s2;
return 0;
}
Select correct answer (single choice)
It prints aleph
It prints an empty string
It prints alpha
Compilation fails
What happens when you attempt to compile and run the following code?
#include <iostream>
namespace SpaceA {
int A;
}
namespace SpaceB {
int A;
}
using namespace SpaceA, SpaceB;
int main() {
SpaceA::A = SpaceB::A = 1;
std::cout << A + 1;
return 0;
}
Select correct answer (single choice)
It prints 2
It prints 1
Compilation fails
It prints 0
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;
}
Select correct answer (single choice)
Compilation fails
It prints 32
It prints 22
It prints 42
Exam
Chapter 4 Assessment - CPA
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;
for(int i = 0; i < 3; i++) {
p = ft[i];
*p = p[1] = *(p + 2) = 10 * i;
}
cout << ft[1][1];
delete [] ft[0];
delete [] ft[1];
delete [] ft[2];
return 0;
}
Select correct answer (single choice)
It prints 10
It prints 20
It prints 30
Compilation fails
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;
cout << s/i + f/i + d/s;
return 0;
}
Select correct answer (single choice)
It prints 6.6
Compilation fails
It prints 4.4
It prints 8.8
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;
cout << s/float(i) + int(f)/i + long(d)/s;
return 0;
}
Select correct answer (single choice)
Compilation fails
It prints 8.8
It prints 8.5
It prints 8.0
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;
}
Select correct answer (single choice)
It prints 2
It prints 3
Compilation fails
It prints 2.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 = 4.4;
cout << f % float(i);
return 0;
}
Select correct answer (single choice)
It prints 0
Compilation fails
It prints 0.2
It prints 2
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "a";
cout << s + "b" + "c";
return 0;
}
Select correct answer (single choice)
It prints abc
It prints ab
Compilation fails
It prints a
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "0123456789";
cout << s.substr(3,7).substr(2).substr();
return 0;
}
Select correct answer (single choice)
It prints an empty string
It prints 34567
Compilation fails
It prints 56789
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1 = "aleph";
string s2 = "alpha";
string s;
s1.swap(s2);
s2.swap(s);
s.swap(s2);
cout << s2;
return 0;
}
Select correct answer (single choice)
It prints aleph
It prints an empty string
It prints alpha
Compilation fails
What happens when you attempt to compile and run the following code?
#include <iostream>
namespace SpaceA {
int A;
}
namespace SpaceB {
int A;
}
using namespace SpaceA, SpaceB;
int main() {
SpaceA::A = SpaceB::A = 1;
std::cout << A + 1;
return 0;
}
Select correct answer (single choice)
It prints 2
It prints 1
Compilation fails
It prints 0
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;
}
Select correct answer (single choice)
Compilation fails
It prints 32
It prints 22
It prints 42
*/