4. What will be the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int arr[] = { 4, 5, 6, 7 };
int* p = (arr + 1);
cout << *arr + 10;
return 0;
}
Options:
a. 12
b. 15
c. 14
d. error
#include <iostream>
using namespace std;
int main()
{
int arr[] = { 4, 5, 6, 7 };
int* p = (arr + 1);
cout << *arr + 10;
return 0;
}
Options:
a. 12
b. 15
c. 14
d. error
5 What would be printed from the following C++ program?
#include <iostream>
using namespace std;
int main()
{
int x[5] = { 1, 2, 3, 4, 5 };
// p points to array x
int* p = x;
int i;
// exchange values using pointer
for (i = 0; i < 2; i++) {
int temp = *(p + i);
*(p + i) = *(p + 4 - i);
*(p + 4 - i) = temp;
}
// output the array x
for (i = 0; i < 5; i++)
cout << x[i] << " ";
return 0;
}
a) 5 4 3 2 1
b) 1 2 3 4 5
c)Address of the elements
d) Canβt say
#include <iostream>
using namespace std;
int main()
{
int x[5] = { 1, 2, 3, 4, 5 };
// p points to array x
int* p = x;
int i;
// exchange values using pointer
for (i = 0; i < 2; i++) {
int temp = *(p + i);
*(p + i) = *(p + 4 - i);
*(p + 4 - i) = temp;
}
// output the array x
for (i = 0; i < 5; i++)
cout << x[i] << " ";
return 0;
}
a) 5 4 3 2 1
b) 1 2 3 4 5
c)Address of the elements
d) Canβt say
6. What will be the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int a = 32, *ptr = &a;
char ch = 'A', &cho = ch;
cho += a;
*ptr += ch;
cout << a << ", " << ch << endl;
return 0;
}
Options:
a. 32, A
b. 32, a
c. 129, a
d. 129, A
#include <iostream>
using namespace std;
int main()
{
int a = 32, *ptr = &a;
char ch = 'A', &cho = ch;
cho += a;
*ptr += ch;
cout << a << ", " << ch << endl;
return 0;
}
Options:
a. 32, A
b. 32, a
c. 129, a
d. 129, A
π1
7,What would be printed from the following C++ program?
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float x = 5.999;
float* y, *z;
y = &x;
z = y;
cout << x << ", " << *(&x) << ", " << *y << ", " << *z << "\n";
return 0;
}
a) 5.999, 5.999, 5.999, 5.999
b) 5.999, 5.9, 5.000, 5.900
c) Address of the elements
d) compilation error
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float x = 5.999;
float* y, *z;
y = &x;
z = y;
cout << x << ", " << *(&x) << ", " << *y << ", " << *z << "\n";
return 0;
}
a) 5.999, 5.999, 5.999, 5.999
b) 5.999, 5.9, 5.000, 5.900
c) Address of the elements
d) compilation error
8 What would be printed from the following C++ program?
#include <iostream>
using namespace std;
int main()
{
int track[] = { 10, 20, 30, 40 }, *striker;
striker = track;
track[1] += 30;
cout << "Striker>" << *striker << " ";
*striker -= 10;
striker++;
cout << "Next@" << *striker << " ";
striker += 2;
cout << "Last@" << *striker << " ";
cout << "Reset To" << track[0] << " ";
return 0;
}
a) 10, 20, 30, 40
b) Striker>10 Next@50 Last@40 Reset To0
c) Striker>10 Next@40 Last@50 Reset To0
d) Striker> Next@ Last@ Reset To
#include <iostream>
using namespace std;
int main()
{
int track[] = { 10, 20, 30, 40 }, *striker;
striker = track;
track[1] += 30;
cout << "Striker>" << *striker << " ";
*striker -= 10;
striker++;
cout << "Next@" << *striker << " ";
striker += 2;
cout << "Last@" << *striker << " ";
cout << "Reset To" << track[0] << " ";
return 0;
}
a) 10, 20, 30, 40
b) Striker>10 Next@50 Last@40 Reset To0
c) Striker>10 Next@40 Last@50 Reset To0
d) Striker> Next@ Last@ Reset To
Q 9 - Choose the respective delete operator usage for the expression βptr=new int[100]β.
A - delete ptr;
B - delete ptr[];
C - delete[] ptr;
D - []delete ptr;
A - delete ptr;
B - delete ptr[];
C - delete[] ptr;
D - []delete ptr;
10 - What is the output of the following program?
#include<iostream>
using namespace std;
main() {
char s[] = "Fine";
*s = 'N';
cout<<s<<endl;
}
A - Fine
B - Nine
C - Compile error
D - Runtime error
#include<iostream>
using namespace std;
main() {
char s[] = "Fine";
*s = 'N';
cout<<s<<endl;
}
A - Fine
B - Nine
C - Compile error
D - Runtime error
int c, *pc;
pc=c; /* Wrong! pc is address whereas, c is not an address. */
*pc=&c; /* Wrong! *pc is the value pointed by address whereas, %amp;c is an address. */
pc=&c; /* Correct! pc is an address and, %amp;pc is also an address. */
*pc=c; /* Correct! *pc is the value pointed by address and, c is also a value. */
pc=c; /* Wrong! pc is address whereas, c is not an address. */
*pc=&c; /* Wrong! *pc is the value pointed by address whereas, %amp;c is an address. */
pc=&c; /* Correct! pc is an address and, %amp;pc is also an address. */
*pc=c; /* Correct! *pc is the value pointed by address and, c is also a value. */
ππanswer 1- 10
1 d compiler error
3 b 10, 20 ,30 ,40, 50,
4 c 14
5 a 5 4 3 2 1
6 c 129, a
7 a 5.999, 5.9999, 5.9999, 5.999
8 b) Striker>10 Next@50 Last@40 Reset To0
9 c delete[] tr;
10 b Nine
1 d compiler error
3 b 10, 20 ,30 ,40, 50,
4 c 14
5 a 5 4 3 2 1
6 c 129, a
7 a 5.999, 5.9999, 5.9999, 5.999
8 b) Striker>10 Next@50 Last@40 Reset To0
9 c delete[] tr;
10 b Nine
AI Programming via @like
Output Questions
π³π³π³π³π³π³π³π³π³π
Question 1.
Find the output of the following program. Assume all required header files are already being included in the program.
void Position(int &C1, int C2 = 3)
{
C1 += 2;
C2 += 1;
}
int main()
{
int P1 = 20, P2 = 4;
Position(P1);
cout << P1 << ", " << P2 << endl;
Position(P2, P1);
cout << P1 << ", " << P2 << endl;
} a, π22, 4 bβ20, 4
22, 6 22, 6
π³π³π³π³π³π³π³π³π³π
Question 1.
Find the output of the following program. Assume all required header files are already being included in the program.
void Position(int &C1, int C2 = 3)
{
C1 += 2;
C2 += 1;
}
int main()
{
int P1 = 20, P2 = 4;
Position(P1);
cout << P1 << ", " << P2 << endl;
Position(P2, P1);
cout << P1 << ", " << P2 << endl;
} a, π22, 4 bβ20, 4
22, 6 22, 6
π1
AI Programming via @like
2 What is the output of this program?
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a) 2 5 10π
b) 2 4 5β
c) 2 6 14π
d) none of the mentionedπ
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a) 2 5 10π
b) 2 4 5β
c) 2 6 14π
d) none of the mentionedπ
π2
AI Programming pinned Β«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Β»
AI Programming via @like
Output Questions π³π³π³π³π³π³π³π³π³π Question 1. Find the output of the following program. Assume all required header files are already being included in the program. void Position(int &C1, int C2 = 3) { C1 += 2; C2 += 1; } int main() { intβ¦
The answer for Q.1 = a