0% found this document useful (0 votes)
3 views2 pages

Tutorial 24

The document is a C++ tutorial that demonstrates the use of pointers and memory addresses. It initializes an array and a variable, prints their initial memory map, updates values through pointers, and then prints the updated memory map. The tutorial illustrates how pointers can be used to manipulate data in memory.

Uploaded by

kdbalke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Tutorial 24

The document is a C++ tutorial that demonstrates the use of pointers and memory addresses. It initializes an array and a variable, prints their initial memory map, updates values through pointers, and then prints the updated memory map. The tutorial illustrates how pointers can be used to manipulate data in memory.

Uploaded by

kdbalke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tutorial 24

#include <iostream>
using namespace std;

int main() {

double a[4] = { 2.3, 4.1, 6.2, 8.3 };


double b = 258.6;
double* c;
double* d;

c = a;
d = &b;

cout << "Initial Memory Map:" << endl;


cout << "Variable Name | Address \t | Value" << endl;
cout << "------------------------------------" << endl;
cout << "a[0] | " << &a[0] << " | " << a[0] << endl;
cout << "a[1] | " << &a[1] << " | " << a[1] << endl;
cout << "a[2] | " << &a[2] << " | " << a[2] << endl;
cout << "a[3] | " << &a[3] << " | " << a[3] << endl;
cout << "b | " << &b << " | " << b << endl;
cout << "*c | " << c << " | " << *c << endl;
cout << "*d | " << d << " | " << *d << endl;

c = c + 3;
*c = 10.4;
*d = 517.2;
cout << "\nUpdated Memory Map:" << endl;
cout << "Variable Name | Address \t | Value" << endl;
cout << "------------------------------------" << endl;
cout << "a[0] | " << &a[0] << " | " << a[0] << endl;
cout << "a[1] | " << &a[1] << " | " << a[1] << endl;
cout << "a[2] | " << &a[2] << " | " << a[2] << endl;
cout << "a[3] | " << &a[3] << " | " << a[3] << endl;
cout << "b | " << &b << " | " << b << endl;
cout << "*c | " << c << " | " << *c << endl;
cout << "*d | " << d << " | " << *d << endl;

return 0;
}

You might also like