+ 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

3rd Jul 2017, 1:15 PM
matteo
matteo - avatar
6 ответов
+ 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
3rd Jul 2017, 1:21 PM
hesham mohamed
hesham mohamed - avatar
+ 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
3rd Jul 2017, 1:33 PM
jay
jay - avatar
+ 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
3rd Jul 2017, 1:25 PM
hesham mohamed
hesham mohamed - avatar
+ 2
very good thanks
3rd Jul 2017, 1:28 PM
matteo
matteo - avatar
+ 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.
4th Jul 2017, 7:15 AM
A.R
A.R - avatar
0
y is an address *y is the value is the address
3rd Jul 2017, 1:25 PM
hesham mohamed
hesham mohamed - avatar