To avoid complications we will post you the questions from 1 upto 10 with some extra notes attached as a screenshoot
• we will post the other 3 qest. tmw. •
• we will post the other 3 qest. tmw. •
1, #include <iostream>
using namespace std;
int main()
{
const int i = 20;
const int* const ptr = &i;
(*ptr)++;
int j = 15;
ptr = &j;
cout << i;
return 0;
}
Options:
a. 20
b. 21
c. 15
d. Compile error
using namespace std;
int main()
{
const int i = 20;
const int* const ptr = &i;
(*ptr)++;
int j = 15;
ptr = &j;
cout << i;
return 0;
}
Options:
a. 20
b. 21
c. 15
d. Compile error
3. What will be the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int num[5];
int* p;
p = num;
*p = 10;
p++;
*p = 20;
p = &num[2];
*p = 30;
p = num + 3;
*p = 40;
p = num;
*(p + 4) = 50;
for (int i = 0; i < 5; i++)
cout << num[i] << ", ";
return 0;
}
Options:
a. 10, 20, 30, 40, 50
b. 10, 20, 30, 40, 50,
c. compile error
d. runtime error
#include <iostream>
using namespace std;
int main()
{
int num[5];
int* p;
p = num;
*p = 10;
p++;
*p = 20;
p = &num[2];
*p = 30;
p = num + 3;
*p = 40;
p = num;
*(p + 4) = 50;
for (int i = 0; i < 5; i++)
cout << num[i] << ", ";
return 0;
}
Options:
a. 10, 20, 30, 40, 50
b. 10, 20, 30, 40, 50,
c. compile error
d. runtime error