Ad

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.


Ad
D
Sections
1
Exercises
#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;
}
Ad

© 2024 Garbage Valuegarbage value logo