
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Get the Value from the Address Using
Pointers
#include
using namespace std;
int main()
{
int var = 5;
// declare pointer variable
int* pointVar;
// store address of var
pointVar = &var;
// print value of var
cout << "var = " << var << endl; // print address of var cout << "Address of var (&var) = " << &var << endl << endl;
// print pointer pointVar
cout << "pointVar = " << pointVar << endl;
// print the content of the address pointVar points to
cout << "Content of the address pointed to by pointVar (*pointVar) = " << *pointVar << endl; return 0; }
Output var = 5 Address of var (&var) = 0x61ff pointVar = 0x61ff Content of the address pointed to by pointVar (*pointVar) = 5
Changing Value Pointed by
Pointers-examples
Common mistakes when working with
pointers
Suppose, we want a pointer varPoint to point to the address of var. Then, int var, *varPoint;
varPoint = var;
*varPoint = &var;
varPoint = &var;
*varPoint = var;
Output 0xffd117ac 0xffd117ac
Here, the pointer ptr is given the value of &f. The output shows that the void pointer ptr stores the address of a float variable f.
Point to Every Array Elements