+ 2
i don't understand the pointers
i am a benniger in the world of c++ and i dont understand the pointer, how do they work and what benefict they have on my program, plese i need a basic explain about pointer
6 odpowiedzi
+ 6
the pointer is used to refer to a specific variable by its address so you can get the value of the variables any time in your program even in different functions or classes the variable value stay the same any whare until you change it of course
+ 9
.
needs address-of operator to assign addresses to pointers.
int x = 2;
int * y = &x; //provide address of x to pointer y
See:
https://code.sololearn.com/cEiG2LA0B51s/?ref=app
+ 3
int x = 2;
int *y = x;
now when i said *y so it refer to the address of y and save 2 it inside the address
and you cant said y = 5 for example because y here is the address and this will generate an error
+ 2
very good thanks
+ 1
Int GrapeJollyRancher = 2;
int *AppleJollyRancher = GrapeJollyRancher;
Let's say the JollyRancher cost 2 cents...we have 2 flavors of Jolly Rancher. By assigning the AppleJollyRancher the same address as the GrapeJollyRancher you are basically saying that they are the same item, same price, just a different flavor-- but they are still both JollyRanchers.
0
y is an address
*y is the value is the address