1. What is the output of the following program?
#include <iostream>
using namespace std;
int main() {
int t[3] = { 3, 2, 1 }, *ptr = t + 1;
(*(ptr + 1))++;
*ptr++;
cout << t[1] << t[2];
return 0;
}
33
22
32
23
2. What is the output of the following program?
#include <iostream>
using namespace std;
int main() {
float x = 3.14, *p = &x;
p[0] = ++x;
cout << x;
return 0;
}
0.0
6.28
4.14
3.14
3. What is the output of the following program?
#include <iostream>
using namespace std;
int main() {
int tab[5] = { 1, 2, 4, 8, 16 };
int *p1 = tab, *p2 = tab + 4;
for(int *p = p1 + 1; p < p2; p++)
*p = p[-1] * 2;
cout << tab[1] << tab[2];
return 0;
}
12
01
, 24
48
4. What is the output of the following program?#include
<iostream>
using namespace std;int main() {
float f[2];
float *p1 = f, *p2 = p1 + 1;
cout << (p2 – p1) / sizeof(float);
return 0;
}
0
2
1
3
5. What is the output of the following program?#include
<iostream>
using namespace std;float fun(float arg) {
return arg * arg + arg + 1;
}
int main() {
cout << fun(fun(1.0));
return 0;
}
16
10
7
13
6. What is the output of the following program?
#include <iostream>
using namespace std;
int fun(float a, float b) {
return a / b;
}
int main() {
cout << fun(fun(1.0,2.0),fun(2.0,1.0));
return 0;
}
0
-1
1
#include <iostream>
using namespace std;
int main() {
int t[3] = { 3, 2, 1 }, *ptr = t + 1;
(*(ptr + 1))++;
*ptr++;
cout << t[1] << t[2];
return 0;
}
33
22
32
23
2. What is the output of the following program?
#include <iostream>
using namespace std;
int main() {
float x = 3.14, *p = &x;
p[0] = ++x;
cout << x;
return 0;
}
0.0
6.28
4.14
3.14
3. What is the output of the following program?
#include <iostream>
using namespace std;
int main() {
int tab[5] = { 1, 2, 4, 8, 16 };
int *p1 = tab, *p2 = tab + 4;
for(int *p = p1 + 1; p < p2; p++)
*p = p[-1] * 2;
cout << tab[1] << tab[2];
return 0;
}
12
01
, 24
48
4. What is the output of the following program?#include
<iostream>
using namespace std;int main() {
float f[2];
float *p1 = f, *p2 = p1 + 1;
cout << (p2 – p1) / sizeof(float);
return 0;
}
0
2
1
3
5. What is the output of the following program?#include
<iostream>
using namespace std;float fun(float arg) {
return arg * arg + arg + 1;
}
int main() {
cout << fun(fun(1.0));
return 0;
}
16
10
7
13
6. What is the output of the following program?
#include <iostream>
using namespace std;
int fun(float a, float b) {
return a / b;
}
int main() {
cout << fun(fun(1.0,2.0),fun(2.0,1.0));
return 0;
}
0
-1
1