Referencje to aliasy nie wskaźniki !

Zdanie w tytule potwierdza taki o to kod
#include < iostream >

int main( ){
int	iTestVariable		=	0;

int &	iReference		=	iTestVariable;
int *	iPointer		=	&iTestVariable;

std::cout	<< "Variable	\tAddress\t"	<< &iTestVariable	<<	"\n"
			<< "Reference	\tAddress\t"	<< &iReference		<<	"\n"
			<< "Pointer	\tAddress\t"	<< &iPointer		<<	std::endl;

	std::system( "pause" );
}
Download main.zip Jak widzimy zmienna iTestVariable oraz referencja do niej ( iReference ) mają ten sam adres więc jest to ten sam „obiekt” pod różnymi nazwami. Zaś wskaźnik jest kompletnie innym obiektem który przechowuję tylko adres zmiennej.

Jeden komentarz o “Referencje to aliasy nie wskaźniki !

Skomentuj Konrad Anuluj pisanie odpowiedzi

Witryna wykorzystuje Akismet, aby ograniczyć spam. Dowiedz się więcej jak przetwarzane są dane komentarzy.