sobota, 15 kwietnia 2017
Shared memory by 2 variables instead of pointers, 2 variables in 1 memory
//Shared memory by 2 variables instead of pointers, 2 variables in 1 memory
//współdzielenie pamięci przez 2 zmienne zamiast wskaźników, 2 zmienne w 1 pamięci
//source:
//http://stackoverflow.com/questions/4629317/what-does-int-mean
// http://www.cplusplus.com/forum/windows/17153/
//author marcin matysek (r)ewertyn.PL
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
void funkcja(int & nb3);
int main()
{
int nb1=0;
int &nb2=nb1;
cout<<"Variable1 value= "<<nb1<<" Its address is: "<<&nb1<<endl;
cout<<"Variable2 value= "<<nb2<<" Its address is: "<<&nb2<<endl;
nb2=10;
cout<<endl;
cout<<"After modifying the 2 variables have value:"<<endl;
cout<<"Variable1 value= "<<nb1<<" Its address is: "<<&nb1<<endl;
cout<<"Variable2 value= "<<nb2<<" Its address is: "<<&nb2<<endl;
funkcja(nb1);
cout<<endl;
cout<<"After leaving the function:"<<endl;
cout<<"Variable1 value= "<<nb1<<" Its address is: "<<&nb1<<endl;
cout<<"Variable2 value= "<<nb2<<" Its address is: "<<&nb2<<endl;
system("pause");
return 0;
}
void funkcja(int & nb3)
{
cout<<endl;
cout<<"in function Variable 3 have value and address of Variable1:"<<endl;
cout<<"Variable3 value= "<<nb3<<" Its address is: "<<&nb3<<endl;
cout<<"after modification Variable 3 ,Variable 3 In function has value:"<<endl;
nb3=20;
cout<<endl;
cout<<"Variable3 value= "<<nb3<<" Its address is: "<<&nb3<<endl;
}
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz