I'm lucky enough to have come to C from assembler, so I intuitively know about local variables being on the stack, and parameters passed through registers. I hope modern teachers make this clear. Funny enough, I learned this as a hobbyist as a kid before going to university to learn computer science
Very useful video btw.. Whenever I get stuck with the cs50 course, i come running to your videos, gain clarity and then rewatch the cs50 content to cement the idea.. If i ever make a how to learn code video, im going to include your channel in it
Huge appreciation, I feel the effort to explain the topic, because you know it's confusing and it needs more attention and extra explanation. Thank you a lot. If I meet in this life: I will give you a BIG HUG
another way to prove it is with the sizeof operator, if you use sizeof on an actual array it will return the number of bytes of the array, if you use sizeof on an array that is a function parameter, it will return 4 or 8 (size of a pointer)
@@PortfolioCourses Update, I got an A+ on my C programming course. Honestly, your C programming examples playlist helped me a lot with saving time and getting straight to the point, unfortunately lots of free sources tend to lack quality.
@@Bayanii1772 That's awesome, congratulations!!!! 😀🥳 I'm so glad to hear the playlist was able to help you out, thank you for taking the time to share this with me!
@@Bayanii1772 Lol, that's generous. In this age of garbage, nothing is more common than describing products/services/content/anything at all as _excellent_ when they are consistently mediocre or worse. It's mind-blowing.
If you have to pass an array to a function, it would be best (if you're not using a struct wrapper) to use foo(size_t size, T array[static size]); to communicate your intentions to whoever is reading your code, as well as to provide the compiler additional info. For passing a pointer to a single value, use foo(T ptr[static 1]); which will allow the compiler to issue warnings if NULL is passed to this function. Iirc, 'T ptr[static N]' means that ptr points to at least N valid objects of type T.
If u pass a array as an argument or return an array, it is basically the same as passing/returning a pointer. I personally never use array as arguments or return value, I just use pointer. I never saw someone use "T array[size]" as an argument, but "T *array" and "size_t size" as additional argument is pretty common. Just use arrays for allocating an array on that stack. For the rest treat array as a pointer, except for indexing maybe (arr[i] is more simple than *(arr+i) ). Passing arrays around is just confusing in my opinion, when it basically behaves like a pointer.
Good day, Mr. Teacher. I got 2 questions: in your video example with arrays how can I a star pointer "*" work without an ampersand "&"? This is the second time I've seen it. First one was this: int main() { char str[] = "All the world's a stage, and all the men and women merely players"; int size = strlen(str); //determining string's length printf("Old line: ");
//print the first word char sep [10]=" "; char* words= strtok (str,sep); //why is star required here? printf("The first word is: %s ", words); return 0; } Why do we need to use "*" after char and how come does it work w/o an ampersand? Hope you'll help =)
This video might help to explain the difference: ruclips.net/video/Qp3WatLL_Hc/видео.html. And this video on pointers too, char * is a pointer type variable: ruclips.net/video/2GDiXG5RfNE/видео.html. :-)
so i have a question. when i print out the array by itself by using the %p specifier i get a memory address being pointed by the array. and when i use the %p in conjuction with &array i get the memory address of where the array variable is stored. then i use the %p for array[0] and i get yet another address. i thought the address pointed by array would be the first element of the array but it is not? this raises the question of why is there an intermediate address between the value stored in array (address) and the first element of array (address). sorry for the long question! Love your videos
@@PortfolioCourses int array[] = {5}; printf("address of array: 0x%p ", &array); printf("address pointed by array: 0x%p ", array); printf("array[0] address: 0x%p ", &array[0]); so i must have made a mistake somewhere before because now its working as i expected it to work! sorry for the confusion!! 😅 thank you for the quick reply!
@@PortfolioCourses I just wanted to say thank you for all your effort towards your long list of comprehensive videos on C! I have been whatching them for a while now and i find it more useful to me to come here everytime i need a refresher or i nneed to understand something, rather than going on a wild search for answers. This last weekend when i posted my question i was studying various topics for an interview that took place monday. I based my study mostly on your videos because YES, they are that good! :) I'm happy to say that you helped me to better prepare myself for the interview and that i got a job position in said company for C in aeronautics. Again, I think mostly anyone who comes across your channel and your tutorials on C agrees with me when i say they are very well made and they are a great source of information and learning. So thank you dearly for all your work!
This is genuinely the best C language tutorial channel in RUclips.
I'm lucky enough to have come to C from assembler, so I intuitively know about local variables being on the stack, and parameters passed through registers. I hope modern teachers make this clear. Funny enough, I learned this as a hobbyist as a kid before going to university to learn computer science
Very useful video btw..
Whenever I get stuck with the cs50 course, i come running to your videos, gain clarity and then rewatch the cs50 content to cement the idea..
If i ever make a how to learn code video, im going to include your channel in it
Thank you very much, I'm so glad to hear these videos help to clarify what is in the CS50 content. :-)
Huge appreciation, I feel the effort to explain the topic, because you know it's confusing and it needs more attention and extra explanation. Thank you a lot. If I meet in this life: I will give you a BIG HUG
You're welcome Naboulsi, and thank you for the kind feedback! :-)
another way to prove it is with the sizeof operator, if you use sizeof on an actual array it will return the number of bytes of the array, if you use sizeof on an array that is a function parameter, it will return 4 or 8 (size of a pointer)
this channel is underrated
Thank you for the support Bayan! :-)
@@PortfolioCourses Update, I got an A+ on my C programming course. Honestly, your C programming examples playlist helped me a lot with saving time and getting straight to the point, unfortunately lots of free sources tend to lack quality.
@@Bayanii1772 That's awesome, congratulations!!!! 😀🥳 I'm so glad to hear the playlist was able to help you out, thank you for taking the time to share this with me!
🎯
@@Bayanii1772 Lol, that's generous. In this age of garbage, nothing is more common than describing products/services/content/anything at all as _excellent_ when they are consistently mediocre or worse. It's mind-blowing.
If you have to pass an array to a function, it would be best (if you're not using a struct wrapper) to use
foo(size_t size, T array[static size]);
to communicate your intentions to whoever is reading your code, as well as to provide the compiler additional info.
For passing a pointer to a single value, use
foo(T ptr[static 1]);
which will allow the compiler to issue warnings if NULL is passed to this function.
Iirc, 'T ptr[static N]' means that ptr points to at least N valid objects of type T.
If u pass a array as an argument or return an array, it is basically the same as passing/returning a pointer. I personally never use array as arguments or return value, I just use pointer. I never saw someone use "T array[size]" as an argument, but "T *array" and "size_t size" as additional argument is pretty common.
Just use arrays for allocating an array on that stack. For the rest treat array as a pointer, except for indexing maybe (arr[i] is more simple than *(arr+i) ). Passing arrays around is just confusing in my opinion, when it basically behaves like a pointer.
So effectively, array as argument in function is really passed by reference.
Thank you for this amazing explanation! 🤩
You're welcome Hazem! :-)
Brillian tutorials!
Nice and clear explanation. Thank you.
You're welcome, I'm glad you enjoyed it! :-)
Incredible stuff. Thank you so so much!!!
You're welcome, I'm glad you enjoyed it! :-)
Good day, Mr. Teacher.
I got 2 questions: in your video example with arrays how can I a star pointer "*" work without an ampersand "&"? This is the second time I've seen it.
First one was this:
int main()
{
char str[] = "All the world's a stage, and all the men and women merely players";
int size = strlen(str); //determining string's length
printf("Old line:
");
//print the first word
char sep [10]=" ";
char* words= strtok (str,sep); //why is star required here?
printf("The first word is: %s
", words);
return 0;
}
Why do we need to use "*" after char and how come does it work w/o an ampersand? Hope you'll help =)
This video might help to explain the difference: ruclips.net/video/Qp3WatLL_Hc/видео.html. And this video on pointers too, char * is a pointer type variable: ruclips.net/video/2GDiXG5RfNE/видео.html. :-)
And of course that pointer is to a variable on the stack, so it wont be around for long :)
What is the editor you are using ? I can see the name is Code ? But when I look for Code for Mac, I only get Visual Studio Code results
Is it Code::Blocks ?
extremely useful thank you so much
You're welcome! :-)
Dude, you are awesome
so i have a question. when i print out the array by itself by using the %p specifier i get a memory address being pointed by the array. and when i use the %p in conjuction with &array i get the memory address of where the array variable is stored. then i use the %p for array[0] and i get yet another address. i thought the address pointed by array would be the first element of the array but it is not? this raises the question of why is there an intermediate address between the value stored in array (address) and the first element of array (address). sorry for the long question! Love your videos
Can you show me the code that you're using to print out these values so I can be sure what is going on? You can just paste it in a comment/reply. :-)
@@PortfolioCourses
int array[] = {5};
printf("address of array: 0x%p
", &array);
printf("address pointed by array: 0x%p
", array);
printf("array[0] address: 0x%p
", &array[0]);
so i must have made a mistake somewhere before because now its working as i expected it to work! sorry for the confusion!! 😅 thank you for the quick reply!
No worries, glad you got it sorted out! :-)
@@PortfolioCourses I just wanted to say thank you for all your effort towards your long list of comprehensive videos on C!
I have been whatching them for a while now and i find it more useful to me to come here everytime i need a refresher or i nneed to understand something, rather than going on a wild search for answers.
This last weekend when i posted my question i was studying various topics for an interview that took place monday.
I based my study mostly on your videos because YES, they are that good! :)
I'm happy to say that you helped me to better prepare myself for the interview and that i got a job position in said company for C in aeronautics.
Again, I think mostly anyone who comes across your channel and your tutorials on C agrees with me when i say they are very well made and they are a great source of information and learning.
So thank you dearly for all your work!
@@franciscojusto4744 WAHOO congratulations Francisco, I'm so happy to hear that!!! 😀
what if i want to make operations at all array elements. should i use for in the function ???
Yes, using a loop like a for loop or while loop would be a good idea. :-)
@@PortfolioCourses thank you very much
You’re welcome! :-)
I'm assuming it's going to be the same for strings. We pass memory addresses aka pointers in string as well?
Yes that's correct, what's really being passed is a pointer (i.e memory address). :-)
What if you return x; in the add function?
Wouldn't that be carried to the main function
Yes, we could return a value to the main function with a return statement, and then perhaps assign the value to the variable a. :-)
Perfect 👍🏻
I'm glad you enjoyed it! 🙂
Excellent =)
Thank you! :-)
That was soooo hard to understand.