10 likes | 143 Views
Referenser. void main (void) { int tal=0; int *tal2=NULL; tal2=&tal; cout<<"change a copy"<<endl; get1(tal); cout<<tal<<" "<<*tal2<<endl; cout<<"change a pointer"<<endl; get2(&tal); //eller get2(tal2); cout<<tal<<" "<<*tal2<<endl; int *tal3=NULL; get2(tal3);
E N D
Referenser void main (void) { int tal=0; int *tal2=NULL; tal2=&tal; cout<<"change a copy"<<endl; get1(tal); cout<<tal<<" "<<*tal2<<endl; cout<<"change a pointer"<<endl; get2(&tal); //eller get2(tal2); cout<<tal<<" "<<*tal2<<endl; int *tal3=NULL; get2(tal3); cout<<"Reset"<<endl; tal=0; cout<<tal<<" "<<*tal2<<endl; get3(tal); cout<<tal<<" "<<*tal2<<endl; } #include <iostream> using namespace std; void get1(int c) { c=5; } void get2(int* c) { if(c!=NULL) *c=5; } void get3(int& c) { c=7; } change a copy 0 0 change a pointer 5 5 Reset 0 0 7 7