So it means that such sintax just simplifies allocation of many bytes. The "const" word in pointer definition means that ones we gave an address to this pointer, we cannot change it ever. Also, it is important to note that allocation of arrays is made in a stack memory (check the adresses - they are reduced when you go further, indexing an array!).
man... on the previous video, you made me more confused about pointers towards the half way mark and onwards... THANK GOD YOU MADE THIS VID TO GO WITH IT!!!
@azkamran, placing the increment operator before the derefrenced pointer just incriments its value, then returns it. As opposed to returning its value, then incrimenting it. therefore, the need to use one or the other is based on the necesity of the situation. not which one is better.
(i write ths comment assuming you said to use the pre-fix incriment because you thought it was better. If you said it just to put it out there, the you now have a little more knowledge either way =) )
I understand that when you use pointers, you are not copying variables. However, I do not get why you would NEED to do it. Why do that instead of copying variables? And in what cases will I NEED to use pointers? This question has been bothering me for months now.. So please help me. Thanks.
@Chaser202 Lets say you only used copied variables to get from the main function to function b. The only way to get the result of function b back to the main function is to "return" it. You would be limited to returning only one variable/result per function ("return" only works once, after that the function stops) The only way to get multiple results from one function back to the main (or to any other function) is via the method discribed in this video (pointers).
in the last video i didn't understand why the increment hasn't take place...ok we r in local world but as we jump to first function ie incremented(var) we have the incremental operator there.....why that x++ cudn't help here...thanks
as explained, the 'x' that is being incremented is a completely different variable than the original one we passed by value. Sure, the local 'x' will definitely be incremented, but not the original one from the other function.
It is interesting that definining an array:
int arr[3]; // as an example
is equivalent to this:
int a;
int b;
int c;
int * const pointer = &a;
So it means that such sintax just simplifies allocation of many bytes. The "const" word in pointer definition means that ones we gave an address to this pointer, we cannot change it ever. Also, it is important to note that allocation of arrays is made in a stack memory (check the adresses - they are reduced when you go further, indexing an array!).
longhorn4500 9 months ago
Is there any way we can change an address that is set?
e.g. int * ptrCow; ptrCow = 0020FA98; // sets ptrCow to point to an address typed in
jehdawg 10 months ago
oh yeah, btw... is it possible to change the ADDRESS of a variable or something like that?
RREEJJEECCTTEEDD 1 year ago
man... on the previous video, you made me more confused about pointers towards the half way mark and onwards... THANK GOD YOU MADE THIS VID TO GO WITH IT!!!
RREEJJEECCTTEEDD 1 year ago
you can also use ++*ptr instead of (*ptr)++
azkamran 2 years ago
@azkamran, placing the increment operator before the derefrenced pointer just incriments its value, then returns it. As opposed to returning its value, then incrimenting it. therefore, the need to use one or the other is based on the necesity of the situation. not which one is better.
(i write ths comment assuming you said to use the pre-fix incriment because you thought it was better. If you said it just to put it out there, the you now have a little more knowledge either way =) )
bandos4lyfe 2 years ago
@bandos4lyfe sorry about my spelling errors on increment =\
bandos4lyfe 2 years ago
it also increments it based on its base class's memory foot print. Its kinda interesting IMO.
scooped13 1 year ago
@azkamran Thats called a prefix expression.
0121ryanh117 1 year ago
Comment removed
azkamran 2 years ago
I feel so accomplised finally understanding pointers. :D Now off to passing by reference!
mattg400194 2 years ago
I understand that when you use pointers, you are not copying variables. However, I do not get why you would NEED to do it. Why do that instead of copying variables? And in what cases will I NEED to use pointers? This question has been bothering me for months now.. So please help me. Thanks.
Chaser202 2 years ago
you will need for memory management.
swisschris104 2 years ago
@Chaser202 Lets say you only used copied variables to get from the main function to function b. The only way to get the result of function b back to the main function is to "return" it. You would be limited to returning only one variable/result per function ("return" only works once, after that the function stops) The only way to get multiple results from one function back to the main (or to any other function) is via the method discribed in this video (pointers).
Cheers,
maik1evers 1 year ago
Very nice! 5 stars.
Achievementmatrix 2 years ago
thanks, i finally understand pointers.
and this video need waaaaaay more views -.-
cptBraver 3 years ago 19
i so agree
tero3 2 years ago 9
lol, agreed--i NEVER could understand pointers--this is the first time it's clear to me =)
tropicallanterns 2 years ago
me either... yaaay
TheBatchGuy 2 years ago
in the last video i didn't understand why the increment hasn't take place...ok we r in local world but as we jump to first function ie incremented(var) we have the incremental operator there.....why that x++ cudn't help here...thanks
shamsdunia 3 years ago 2
as explained, the 'x' that is being incremented is a completely different variable than the original one we passed by value. Sure, the local 'x' will definitely be incremented, but not the original one from the other function.
antiRTFM 3 years ago
if i was to get something that listed memory addresses can i alter them?
ur tutorials rock !!
bradmasterx 3 years ago
I just found your videos and you explain good man :)
can you tell me how do we know when to return a & or a const function and when not to retunr one? this is a confusing issue!
NajanJan 3 years ago
that's called a "reference" as we will (hopefully) learn about soon
antiRTFM 3 years ago
u the best
ghostman515005 3 years ago
pls. do 46 soon
hero3bash 3 years ago