Passing an Array to a Function | C Programming Tutorial

  Рет қаралды 43,931

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 51
@danielcarpio4302
@danielcarpio4302 2 ай бұрын
This is genuinely the best C language tutorial channel in KZbin.
@mikehibbett3301
@mikehibbett3301 9 ай бұрын
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
@SketchupGuru
@SketchupGuru 2 жыл бұрын
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
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you very much, I'm so glad to hear these videos help to clarify what is in the CS50 content. :-)
@naboulsikhalid7763
@naboulsikhalid7763 Жыл бұрын
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
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Naboulsi, and thank you for the kind feedback! :-)
@Bayanii1772
@Bayanii1772 Жыл бұрын
this channel is underrated
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you for the support Bayan! :-)
@Bayanii1772
@Bayanii1772 Жыл бұрын
@@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.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@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!
@lucasgroves137
@lucasgroves137 Жыл бұрын
🎯
@lucasgroves137
@lucasgroves137 Жыл бұрын
@@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.
@Brad_Script
@Brad_Script 5 ай бұрын
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)
@LeeHongYee99
@LeeHongYee99 10 ай бұрын
So effectively, array as argument in function is really passed by reference.
@john.darksoul
@john.darksoul 9 ай бұрын
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.
@xCwieCHRISx
@xCwieCHRISx 9 ай бұрын
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.
@a.v7998
@a.v7998 11 ай бұрын
Brillian tutorials!
@hazemba2669
@hazemba2669 2 жыл бұрын
Thank you for this amazing explanation! 🤩
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome Hazem! :-)
@Acksakal
@Acksakal Жыл бұрын
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 =)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
This video might help to explain the difference: kzbin.info/www/bejne/h6GWiJSqgbGSfsU. And this video on pointers too, char * is a pointer type variable: kzbin.info/www/bejne/aHinmot9areZhKc. :-)
@yunustan7502
@yunustan7502 Жыл бұрын
Nice and clear explanation. Thank you.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome, I'm glad you enjoyed it! :-)
@flywittzbeats4008
@flywittzbeats4008 Жыл бұрын
Incredible stuff. Thank you so so much!!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome, I'm glad you enjoyed it! :-)
@mikehibbett3301
@mikehibbett3301 9 ай бұрын
And of course that pointer is to a variable on the stack, so it wont be around for long :)
@heshamgad-yh9vs
@heshamgad-yh9vs Жыл бұрын
Dude, you are awesome
@ddlc7022
@ddlc7022 6 ай бұрын
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
@ddlc7022
@ddlc7022 6 ай бұрын
Is it Code::Blocks ?
@SketchupGuru
@SketchupGuru 2 жыл бұрын
I'm assuming it's going to be the same for strings. We pass memory addresses aka pointers in string as well?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Yes that's correct, what's really being passed is a pointer (i.e memory address). :-)
@hyperphenomenal4360
@hyperphenomenal4360 Жыл бұрын
extremely useful thank you so much
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@SketchupGuru
@SketchupGuru 2 жыл бұрын
What if you return x; in the add function? Wouldn't that be carried to the main function
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Yes, we could return a value to the main function with a return statement, and then perhaps assign the value to the variable a. :-)
@franciscojusto4744
@franciscojusto4744 Жыл бұрын
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
@PortfolioCourses Жыл бұрын
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. :-)
@franciscojusto4744
@franciscojusto4744 Жыл бұрын
@@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
@PortfolioCourses Жыл бұрын
No worries, glad you got it sorted out! :-)
@franciscojusto4744
@franciscojusto4744 Жыл бұрын
@@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!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@franciscojusto4744 WAHOO congratulations Francisco, I'm so happy to hear that!!! 😀
@mahmoudelhanafy89
@mahmoudelhanafy89 Жыл бұрын
what if i want to make operations at all array elements. should i use for in the function ???
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Yes, using a loop like a for loop or while loop would be a good idea. :-)
@mahmoudelhanafy89
@mahmoudelhanafy89 Жыл бұрын
@@PortfolioCourses thank you very much
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome! :-)
@emtnan1733
@emtnan1733 2 жыл бұрын
Perfect 👍🏻
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I'm glad you enjoyed it! 🙂
@NikitaSafronov-y6i
@NikitaSafronov-y6i 2 жыл бұрын
Excellent =)
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you! :-)
@raziamim9510
@raziamim9510 3 ай бұрын
That was soooo hard to understand.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 90 М.
array vs &array Pointers Difference Explained | C Programming Tutorial
17:38
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 90 МЛН
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 14 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 24 МЛН
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 4,2 МЛН
C_96 Passing Array as an Argument to a Function in C | C Language Tutorials
27:37
Jenny's Lectures CS IT
Рет қаралды 180 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 66 М.
Pass By Reference | C Programming Tutorial
10:12
Portfolio Courses
Рет қаралды 38 М.
Call By Value & Call By Reference in C
8:34
Neso Academy
Рет қаралды 1,3 МЛН
Function Basics | C Programming Tutorial
15:36
Portfolio Courses
Рет қаралды 72 М.
Passing Array as an Argument to a Function
3:14
Neso Academy
Рет қаралды 283 М.
MAX EVERYTHING! WoW Rep Farm in War Within!
MarcelianOnline
Рет қаралды 45
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 90 МЛН