C++ Tutorial (45 updated 1) - Absolute n00b spoonfeed
Uploader Comments (antiRTFM)
Top Comments
-
thanks, i finally understand pointers.
and this video need waaaaaay more views -.-
-
i so agree
All Comments (25)
-
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!).
-
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
-
oh yeah, btw... is it possible to change the ADDRESS of a variable or something like that?
-
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!!!
-
@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,
-
@azkamran Thats called a prefix expression.
-
it also increments it based on its base class's memory foot print. Its kinda interesting IMO.
-
@bandos4lyfe sorry about my spelling errors on increment =\
-
@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 =) )
-
you can also use ++*ptr instead of (*ptr)++
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