Chapter - 3: Graduating to C++

Create four integers, four pointers to these integers and four references to them. Store pointers and references in two arrays ans print out the values of four integers using these arrays.


D
Sections
4
Exercises
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
	int a = 1, b = 2, c = 3, d = 4;
	int *w = &a, *x = &b, *y = &c, *z = &d;
	int &p = a, &q = b, &r = c, &s = d;

	int *arr1[4] = { w, x, y, z };
	int arr2[4] = { p, q, r, s };

	for (int i = 0; i < 4; i++)
	{		
		//printing values using pointers
		cout << *arr1[i] << " ";

		//printing values using references
		cout << arr2[i] << endl;
	}

	getch();
	return 0;
}

© 2021 Garbage Valuegarbage value logo