Chapter - 3: Graduating to C++

In the following program how would you define q, if the first cout is to output "Internet" twice, whereas, the second cout is to output "Intranet" twice.


D
Sections
1
Exercises

A

B

C

D

1

2

3

4

5

6

7

8

9

10

#include<iostream>

using namespace std;

int main()
{
	char *p = "Internet";
	cout << p << endl << q << endl;
	q = "Intranet";
	cout << p << endl << q << endl;
	return 0;
}

Answer :

#include<iostream>

using namespace std;

int main()
{
	char *p = "Internet";
	char *q;
	q = p;
	cout << p << endl << q << endl;
	q = "Intranet";
	p = q;
	cout << p << endl << q << endl;
	return 0;
}

© 2020 Garbage Valuegarbage value logo