Sunteți pe pagina 1din 3

Un program in C++ configureaza urmatoarea zona de memorie.

Variabilele
sunt pointeri de tip intreg. Scrieti programul si realizati corespondenta adreselor
date in sistemul de numeratie zecimal cu adresele date de program in sistemul
de numeratie hexazecimal.
Pe cati octeti se scriu variabilele?
De ce ne afiseaza valori diferite pentru aceiasi variabila?
b
***x

a
*y

z
*z

**y

*x

2293484

**x

2293488

2293492

2293496

2293500

adresele variabilelor

***x = **y = *z = b = 2; (variabile de tip intreg)


***x = **y = *z = b; aplicam functia & (extrage adresa unui pointer);
(&*)**x = (&*)*y = (&*)z = &b; functiile * si & sunt functii inverse lasa obiectul asupra caruia actioneaza
neschimbat;
**x = *y = z = &b = 2293484;
**x = *y

(&*)*x = &*y

*y =z

&*y = &z

**x = z

*x = &z;

b
*y

*x = y

2
2293484

x = &y

y = &z

**x = &b

a
**y

&*x =&y

*(&z) =&b
y

z = &b ;
x

rezulta:

*x

**x

22934
84

***x

*z

229348
4
2293488

22934 22934 22934 22934


92
96
92
84

2293492

2293496

2293500

23 August 2014
Profesor Vasilescu
Dumitru

#include <iostream>
using namespace std;

int main()
{
cout << "Starting..." << endl;
int ***x ;
int **y ;
int *z ;
int a = 1, b = 2 ;
z = &a ;
y = &z ;
x = &y ;
cout<< **y<< endl ; //afiseaza 1
**x = &b ;
cout<< **y <<endl ;

//afiseaza 2

cout<<x<<"; " <<*x<<"; "<<**x<<"; "<<***x<<endl;


//

22fef8;

22fef4;

22feec;

cout<<y<<"; "<<*y<<"; "<<**y<<endl;


//

22fef4;

22feec;

cout<<z<<"; "<<*z<<endl;
//22feec;

cout<<&x<<"; "<<&y<<"; "<<&z<<"; "<<&a<<"; "<<&b<<endl; //


//

22fefc

return 0;
}

22fef8

22fef4

22fef0

22feec

S-ar putea să vă placă și