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

Tutorial 25

The document is a C++ tutorial that demonstrates the use of pointers and memory addresses with a 2D array and a double variable. It initializes a 2x2 array and a double variable, then displays their memory addresses and values before and after modifying them through pointers. The tutorial emphasizes understanding memory mapping and pointer manipulation in C++.

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)
5 views2 pages

Tutorial 25

The document is a C++ tutorial that demonstrates the use of pointers and memory addresses with a 2D array and a double variable. It initializes a 2x2 array and a double variable, then displays their memory addresses and values before and after modifying them through pointers. The tutorial emphasizes understanding memory mapping and pointer manipulation in C++.

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 25

#include <iostream>
using namespace std;

int main() {

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


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

c = a[0];
d = &b;

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


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

return 0;
}

You might also like