Тёмный

array vs &array Pointers Difference Explained | C Programming Tutorial 

Portfolio Courses
Подписаться 195 тыс.
Просмотров 38 тыс.
50% 1

The difference between the array and &array pointers in C is explained, i.e. the difference between when an array decays to a pointer and when we use the & operator with the array. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Опубликовано:

 

23 июл 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 152   
@thanostzia
@thanostzia 6 месяцев назад
This video is a must-watch for any C programmer. The concept of arrays vs pointers, the decaying of arrays into pointers and how everything is handled in memory is crucial in understanding C.
@PortfolioCourses
@PortfolioCourses 6 месяцев назад
I’m glad you enjoyed it! :-)
@succerzxix1950
@succerzxix1950 7 месяцев назад
This guy is an absolute legend. Just when i though i had mastered pointers, the concept manages to leave me bamboozled again. Thank you for your amazing work! ❤
@avixx
@avixx Месяц назад
Your programming language tutorials are one of best on YT, amazing job!
@justwalk7063
@justwalk7063 Год назад
This is the first channel I look at when there is something I don't understand about the subject.I can find everything I'm looking for, even what I'm not looking for 😄. Thank you for such valuable information. 😊
@PortfolioCourses
@PortfolioCourses Год назад
Thank you so much for this positive feedback, hearing things like this is so encouraging to me and I really appreciate it. :-)
@Chic_Vixen
@Chic_Vixen Год назад
Me too, I often try to try to look for alternative channels so my view is not too concentric. But I always find I have to return here. Best channel for c
@armanlodhra7995
@armanlodhra7995 2 года назад
really good video. really helpful how you formatted the print statements so that everything was in line. You do the small things really well.
@PortfolioCourses
@PortfolioCourses 2 года назад
Thank you for the kind feedback Arman, I really appreciate that! 😀
@infas_mhd
@infas_mhd Год назад
Every small detail about c is crystal clear here in this channel..Keep it up bro...
@PortfolioCourses
@PortfolioCourses Год назад
Thank you very much for sharing this positive feedback! :-) It means a lot to me that these videos are helpful, I’m glad to hear they are clearing up details.
@duldulatori3123
@duldulatori3123 Год назад
Mr. all of your videos are 100% understandable unlike lecturers at my university. well done !
@PortfolioCourses
@PortfolioCourses Год назад
Thank you very much for the positive feedback, I'm really glad to hear you're finding the videos understandable. 🙂
@duldulatori3123
@duldulatori3123 Год назад
​@@PortfolioCourses Like for real , If I had lecturer like you , I would not dislike C/C++ as I do now, but as you make topics clear, I am kinda getting in "like" with C ,thanks 😁
@PortfolioCourses
@PortfolioCourses Год назад
@@duldulatori3123 Hahaha aww thanks again for the kind feedback, and you're welcome! 🙂
@marcellogambetti9458
@marcellogambetti9458 2 месяца назад
passed all the morning watching videos on array dacay on other guys' "famous" channels, BUT your explainations are ALWAYS the best, precise, concise, starting from scratch and working up. GREAT WORK!
@nukarajupavani937
@nukarajupavani937 2 месяца назад
With just this one video, you throw a clear examole of an" ideal teacher with a great depth of knowledge about every single concept".Sir,PLEASE PLEASE MAKE a Playlist for DSA as it is absolutely crucial and difficult. A teacher like you ought to teach such critical concepts,kindly understand. Thank you soooo much for the videos and hope you do a dsa course for us needy.
@mohammedal-twaity7521
@mohammedal-twaity7521 Год назад
Your explanation is the best explanation I've ever seen. I grasped so many things from your videos and I am still watching them; thanks a million Dr Kevin.
@PortfolioCourses
@PortfolioCourses Год назад
Thank you very much Mohammed! :-)
@kitchenchem141
@kitchenchem141 Год назад
Been a minute since I’ve worked with memory/C, this was immensely helpful and probably saved countless hours. Thanks!
@PortfolioCourses
@PortfolioCourses Год назад
You’re welcome, I’m so glad to hear this was helpful for you! :-)
@hansdampf2284
@hansdampf2284 2 месяца назад
I think this videos is showing the differences between arrays and pointers in C quite well. It also gets real quirky when you add memory areas you got with malloc and treated like an array to the mix
@R_C001
@R_C001 Год назад
I've spent days trying to find a resolution to my confusion, in differentiating 'array' and '&array'. This video was extremely helpful, subbed.
@PortfolioCourses
@PortfolioCourses Год назад
That's excellent to hear this video was able to help you out, and welcome aboard! :-)
@christopheanfry2425
@christopheanfry2425 5 месяцев назад
I love your videos going full c and your videos help me so much to understand these tricky concepts. Thanks again 🙏
@vadimgerasimenko4904
@vadimgerasimenko4904 Месяц назад
Thank you for sharing knowledges and source code!
@nameless5724
@nameless5724 Год назад
AWESOME!!!! Please, keep doing this kind of videos! Thank you!!!
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! 😀
@CuriousCyclist
@CuriousCyclist Год назад
These videos deserve a lot more views. They are really good. Thanks.
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome, and thank you very much for the kind words... the traffic on the channel has grown a lot of the last year, hopefully it keeps growing. :-)
@fifaham
@fifaham Год назад
Very interesting explanation. I studied C very long years ago, your videos are great refresh to details many programmers don't pay attention to. Thank you Kevin.
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome Firas! :-)
@Algebraiic
@Algebraiic Год назад
the pointer arithmetic side of arrays are so cool, and your video just made it better!
@PortfolioCourses
@PortfolioCourses Год назад
I agree it is cool, and I’m glad you enjoyed the video! :-)
@Rafael-fp9xc
@Rafael-fp9xc 5 месяцев назад
I made some tests about pointers and pointers to an entire array, and I found that if you dereference a pointer to an entire array like a int (*)[5], it will obtain a pointer int * to the first element on this array pointer. So that's why in 11:00 momment was printed an adress. To get the correct behaviour, you need to add an extra dereference operator *, and the line will be: printf(" **(matrix[1] + 1): %zu ", **(matrix[1] + 1)); So the dereference order stays: int (*)[5] -> int * -> int Which is similar to: int ** -> int * -> int But the int ** and int (*)[5] types aren't interchangeable Curiosity: The names of a N-Dimensional matrix decay to pointers to an entire first (N-1)-Dimentional Array of the N-Dimensional Array, excluding the n = 1 case. Then we have: int array1[5]; //1D int array2[5][5]; //2D int array3[5][5][5]; //3D Therefore: array1 decays to a int * to the first element. This case is exclusive to the rule. array2 decays to a int (*)[5] to the first row of the matrix, and a row is a 1D array. array3 decays to a int(*)[5][5] to the first 2D matrix of the 3D matrix. Another Curiosity: If you use the reference operator & in a matrix instead of either a matrix row or in a vector, you will obtain a pointer to an entire matrix, and the type stays something like int (*)[3][5], and the order of the dereference stays: int (*)[3][5] -> int(*)[5] -> int * -> int And the detail is that these operations, all of them, returns the first element, row or matrix of the array referenced. Then if I have a 3D multidimensional like this: int matrix[5][5][5]; &matrix -> pointer to the entire 3D matrix &matrix[0] -> pointer to the FIRST 2D matrix in the 3D matrix &matrix[0][0] -> pointer to the FIRST ROW in the FIRST 2D matrix in the 3D matrix &matrix[0][0][0] -> pointer to the FIRST ELEMENT in the FIRST ROW in FIRST 2D matrix in the 3D matrix.
@viigihabe
@viigihabe 3 месяца назад
Yeah, I did play around, too. But because of the line where he type-casted to int*. In my opinion it would be more correct just to add square brackets to actually get the int* out of it: (&matrix[1] + 1)[0]; Although I kinda expected to get actual int value out of it, but instead it gives a pointer. But again, reinterpreting address through type-cast in this case is not correct even though it works. Adding index operator eliminates all the casts. But sure in this explanatory video it gives deeper understanding about the addresses and "everything is an int unless you tell that it's something else". By the way, he got a warning, but it still compiled. In c++ you get straight compilation error. Can't do that without a cast or extra dereference as you did or as I did.
@satvikkhare1844
@satvikkhare1844 Год назад
simply brilliant, these questions are asked in interviews to check proficiency of the candidate in pointers
@PortfolioCourses
@PortfolioCourses Год назад
Thank you for the positive feedback Satvik, I hope this video is able to help people with those interview questions! :-)
@choppinbrixx4931
@choppinbrixx4931 Год назад
Bravo dude! You have a gift for teaching so clearly. I was just looking at the main function second parameter this morning, how you can write char *argv[] or char **argv, and I couldn't get it...but watching this made it click. Thank you!
@PortfolioCourses
@PortfolioCourses 11 месяцев назад
You're very welcome, I'm glad the video helped make it click! :-D
@lisandroiaffar4501
@lisandroiaffar4501 5 месяцев назад
Excellent video, thank you so much!
@Exoepxoe
@Exoepxoe 3 месяца назад
amazing, thank you very much for this fantastic video.
@selimsagr446
@selimsagr446 Год назад
All videos are great! But this one solved one of the problem I struggle to understand always :) Thanks.
@PortfolioCourses
@PortfolioCourses Год назад
That's awesome, glad to hear that Selim, and you're welcome! 😀
@ሰውመሆን
@ሰውመሆን Год назад
your videos are clear and with good examples. thank you sir
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome Robel! :-) I'm glad that you find the examples are good and the videos clear.
@Guidoev2
@Guidoev2 8 дней назад
Thank you very much for this thorough explanation, you provided an invaluable insight, and I'm very grateful for it
@PortfolioCourses
@PortfolioCourses 7 дней назад
You’re very welcome! :-)
@Mnogojazyk
@Mnogojazyk 2 года назад
I’m glad I found your course and videos. But wonder I nearly failed C lo those many decades ago.
@PortfolioCourses
@PortfolioCourses 2 года назад
I’m glad you found them too! One of the better programmers I know failed introductory programming 3 times.
@user-yw8yy4qy3y
@user-yw8yy4qy3y 10 месяцев назад
very good explanation thanks for your helpful videos
@sravanakumar9326
@sravanakumar9326 Год назад
Wow, such a great explanation 🎉
@PortfolioCourses
@PortfolioCourses Год назад
I’m glad you enjoyed it Sravana! :-)
@dimitrioskalfakis
@dimitrioskalfakis Год назад
good and useful points. nice clean method of presenting essential topics.
@PortfolioCourses
@PortfolioCourses Год назад
I'm glad you enjoyed it Dimitrios! :-)
@1nonly_user
@1nonly_user 14 дней назад
i mean this is what i was exactly looking for , thank u so much ❤
@PortfolioCourses
@PortfolioCourses 14 дней назад
You’re very welcome! :-)
@ismbks
@ismbks 4 месяца назад
terrific instructor
@PortfolioCourses
@PortfolioCourses 4 месяца назад
I'm glad you're enjoying the teaching! :-)
@walidoulondon8107
@walidoulondon8107 4 месяца назад
This guy is a legend greeting from England ❤
@PortfolioCourses
@PortfolioCourses 4 месяца назад
Thank you, greetings from Canada! :-)
@khomo12
@khomo12 3 месяца назад
Nice!👍👍👍
@matheusbatista715
@matheusbatista715 Год назад
Great video! Thanks!
@PortfolioCourses
@PortfolioCourses Год назад
You’re welcome Matheus, I’m glad you enjoyed it! :-)
@matheusbatista715
@matheusbatista715 Год назад
@@PortfolioCourses With this piece of code below, I got a SEGFAULT. I thought the problem was " char *str = string1; ". So I changed it to " char *str = (char *) &string1; " and now everything works just fine. But I don't really really know why is that. In my head, if I passed the adress of the first char of string literal it would iterate just fine... I know that I have to pass the adress of the entire chunck ... Can you explain this one? Thanks for considering my request! int main(){ const char *string1 = "18e22cd2188f"; const char *string2 = "18E22CD2188F"; char *str = string1; while (*str) { *str = toupper((unsigned char) *str); str++; } printf(" "); for(int k = 0; string2[k]; k++){ printf("%c" , string2[k]); } return 0; } PS: Sorry if I made any grammar mistakes. English is not my first language.
@PortfolioCourses
@PortfolioCourses Год назад
@@matheusbatista715 I think you have the right idea.. string1 would give you the address of the first char, and that is what you want to assign to str. The issue is that string1 is a const char pointer but str is a char pointer. So I think that's why a typecast to (char *) made it work. 🙂
@tails_the_god
@tails_the_god Год назад
THANK YOU SIR!
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome! 😀
@justcurious1940
@justcurious1940 Год назад
Thanks Dr kevin, well explained as usual , the term 2D array makes it more complex to understand I like to break it like this : matrix[3][5] is an array of 3 elements of type int[5], now I can see how can I declare a pointer of type int[5] (or pointing to an element of type int[5]) that will point of the first element of matrix, int (*pointer_matrix)[5] = matrix ; same as ----- > int (*pointer_matrix)[5] = &matrix[0] ; if I do something like this : int(*pointer_matrix)[5] = matrix[0] ; it will be wrong because matrix[0] will be decayed into a pointer of type (int*) instead of (int(*)[5] ) it gets more complex with functions 🙃🙃.
@PortfolioCourses
@PortfolioCourses Год назад
Thanks for sharing!
@tornado-zex47
@tornado-zex47 Год назад
best of luck keep going
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! 🙂
@cipherxen2
@cipherxen2 2 месяца назад
There are very few concepts you need to understand to master pointers. Most important is understanding 'type of pointer'.
@fadieid5638
@fadieid5638 2 года назад
Love it 😍
@PortfolioCourses
@PortfolioCourses 2 года назад
I'm glad to hear you love it! :-D
@maorberenstein2540
@maorberenstein2540 Год назад
You are a god teacher man I love you
@PortfolioCourses
@PortfolioCourses Год назад
Thank you for the love Maor! :-)
@neon7874
@neon7874 Год назад
nice pls post more finding.
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! And I'm just curious, what do you mean by more finding? Like finding elements in arrays? Or more videos like this? I'm just curious. :-)
@hlubradio2318
@hlubradio2318 3 месяца назад
Wow will I ever need to use it?
@CZghost
@CZghost 4 месяца назад
So that's pretty much useful to calculate the size of the array.
@paulabraham2550
@paulabraham2550 3 месяца назад
Pointer arithmetic was Ritchie's biggest mistake. In general C keeps things simple as it should . But in the case of pointer arithmetic it's trying to be too "helpful" so that you don't have to be explicit as a coder. That just makes it confusing: if "+1" just meant "add one" all this confusion would go away. KISS, Dennis. KISS!
@PortfolioCourses
@PortfolioCourses 3 месяца назад
In general when looking at older tech/languages/etc like C, I find it incredible how decisions made by one person or even a handful of individuals last on and have ramifications decades later.
@dutta.alankar
@dutta.alankar 3 месяца назад
It is perhaps worth mentioning that sizeof is a function where this decay of array pointers don’t happen.
@PortfolioCourses
@PortfolioCourses 3 месяца назад
sizeof() is not a function, it’s an operator: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2wNc15926X4.html
@dutta.alankar
@dutta.alankar 3 месяца назад
@@PortfolioCourses Thanks for pointing out this video!
@Abake-117
@Abake-117 3 месяца назад
Thank you making this video! Everything regarding arrays/pointers makes way more sense now. However, I am trying to replicate what you have discussed on one of my Ubuntu VMs using VSCode. I am running into a format error in which my compiler is saying that %zu expects an argument of type size_t. I know I can just use %p to see the hex, however, I would like to see the decimal notation as you have shown in the video. Any recommendations/suggestions? Thanks!
@DavidLindes
@DavidLindes Год назад
Nice video! One humble request, re 8:07: I'd love it if you'd use the term parentheses here, and save the word brackets for specifically the [] characters. I know it sometimes also gets used to just talk about the idea of bracketing something in something else, and thus can apply to (), {}, [], and even ... I just find that it nice to call those parentheses (or "round brackets"), braces ("curly brackets"), brackets ("square brackets'), and chevrons ("angle brackets"), and keep things specific. Again, you're not wrong, just a humble request.
@PortfolioCourses
@PortfolioCourses Год назад
You know that's really interesting, I just went down the rabbit hole of reading about all the different kinds of brackets and all the different names for them. :-) In the school system that I grew up in it was common to call all of those brackets, and then to make distinctions when necessary like square brackets, round brackets, "squiggly brackets", etc. I'll think about that for future videos though.... I usually try to use whatever language is more common, but I have exceptions... I pronounce "char" in a way that's not incorrect ("car"), but it's rare. It's hard to break 20-30 year habits haha...
@DavidLindes
@DavidLindes Год назад
@@PortfolioCourses haha, yeah… I think I say char like car sometimes, and like care other times, and I haven’t put enough introspection into figuring put when or why I choose one or the other, I just know I use both. :) As for what’s common, I imagine maybe there are regional variations or something?? Like, I don’t think I ever heard anyone using brackets in a generic way until a few years ago… but now I’ve heard it a number of times. So… I don’t know what changed, but… yeah. Thank you for taking it as a gentle request for the future, as intended. And certainly if you forget, no big deal. :)
@PortfolioCourses
@PortfolioCourses Год назад
Yes I suspect it's regional, in Canada brackets is "mostly" used but parentheses is also used.
@DavidLindes
@DavidLindes Год назад
@@PortfolioCourses yeah… well, I don’t remember ever hearing it in Silicon Valley in the 1990’s and early 2000’s, but then when I went back there circa 2015, I was starting to. So… 🤷🏻‍♀️
@prakhartiwari7537
@prakhartiwari7537 Год назад
Great
@PortfolioCourses
@PortfolioCourses Год назад
Thank you Prakhar! :-)
@jawadikram5989
@jawadikram5989 Год назад
Let’s go!!!
@PortfolioCourses
@PortfolioCourses Год назад
Haha I love the enthusiasm! :-)
@vicsteiner
@vicsteiner 14 часов назад
My compiler - gcc on Ubuntu - says I should use %ls instead of %zu, but then when I use it it just does not print the address. Very odd, nio idea what is going on. I do can make it work with %ld but also get the same warning as with &zu.
@muhisaleh4598
@muhisaleh4598 Год назад
thanks for this Video :) in order to make peace with douple pointer 😅 can you just please make a video about douple Pointer and espicially descripe how to use douple pointer in oeder to creat an array of Strings!! :)
@PortfolioCourses
@PortfolioCourses Год назад
Hmm maybe one day I can make a video on "double pointers" that's a good idea thanks! 🙂I do have this video on dynamically allocating an array of strings: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-4_2BEgOFd0E.html.
@muhisaleh4598
@muhisaleh4598 Год назад
@@PortfolioCourses thank you very much 🙈😇
@PortfolioCourses
@PortfolioCourses Год назад
@@muhisaleh4598 You're welcome! 🙂
@muneerbasha1958
@muneerbasha1958 Год назад
Sir, please make a video on function pointer as member of array of structures
@PortfolioCourses
@PortfolioCourses Год назад
One day I might do that Muneer, I dont know when though. :-)
@06watta
@06watta Год назад
Hey man quick question what IDE do you use I see a lot of youtubers use it.
@PortfolioCourses
@PortfolioCourses Год назад
In this video I’m using Xcode on a Mac. :-)
@goktugparlak1618
@goktugparlak1618 Год назад
why when we do sizeof(array) it returns the (byte of int )*number of elements if it is the pointer of the first element why it did not return just 4 byte all of the time
@PortfolioCourses
@PortfolioCourses Год назад
When we have an array like: int array[10], then if we are using 'array' like an array and not like a pointer, then 'array' is not a pointer to the first element. It's really an array of 10 ints, and so sizeof(array) will give us the size of that array. BUT if we ARE using an array like a pointer, say we have "*(array + 1)" and do some pointer arithmetic to get the 2nd element of the array, then what happens is that the array "decays to a pointer". And "array" in this case decays to to a "pointer to the fist element". So arrays like this become ("decay to") a pointer to the first element when we treat them like pointers. :-)
@zoquevil4792
@zoquevil4792 Год назад
Please sir, do you have some examples about : pointer to an array VS pointer to a pointer, when and how to use this particular pointer if we want to find for example the size of the array ... I 'm confused and wanted to clarify this point please... (why sometime we write **ar and not *ar[] espacially when the size of the array is dynamically allocated. I thing this is why in the main function we have main(int argc, char *argv[]) Thanks !
@PortfolioCourses
@PortfolioCourses Год назад
I don't have any examples of this yet, but this is a good idea for a future video so I will add this to my list. :-) Though that said, I'm not sure if we *can* get the size of an array when have *ar[], I believe that's why we need argc in the case of the main function.
@zoquevil4792
@zoquevil4792 Год назад
@@PortfolioCourses Thanks for your response Yep for a new video 🙃!!💪!!! ... I just saw your example "ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-4_2BEgOFd0E.html" // Dynamically Allocate Memory For An Array Of Strings // very interesting too!
@yclept9
@yclept9 7 месяцев назад
What about char *argv[]? Array of pointers to char with indefinite size.
@emerior-x-brawlstars551
@emerior-x-brawlstars551 Год назад
ti (the instrunt into the channel rack) and then it crashes the soft soft... Can soone help please?
@PortfolioCourses
@PortfolioCourses Год назад
I'm not sure what you're asking, maybe someone else can help.
@SIVAJI_333
@SIVAJI_333 Год назад
13:22 what if the statement modified as "int *pointer[5] = &matrix[1] + 1;" ? & the warning will go away or not?
@justcurious1940
@justcurious1940 Год назад
If u modified that statement to : "int *pointer[5] = &matrix[1] + 1;" ? u will get a scary red message instead of a cute orange warning. from my little knowledge I think u are trying to initialize an array of pointers pointing to an int with a pointer pointing to an array of 5 integers I'm not sure about my explanation above but I'm sure that u cannot initialize an array with another array directly using the = operator , u can initialize the elements of the array 1 by 1 using a loop or use memcpy to do it at once.
@PortfolioCourses
@PortfolioCourses Год назад
With things like this it's great to give it a try and see! :-) If we make that change pointer would become an array of 5 int pointers and we will get an error.
@justcurious1940
@justcurious1940 Год назад
sorry my first reply was not related to the video, all u have to do is adding parentheses around the variable (pointer) and the asterisk like this : int (*pointer)[5] = &matrix[1] + 1; // now the variable (pointer) is a pointer pointing to an object of type int[5]
@PortfolioCourses
@PortfolioCourses Год назад
Thanks for sharing that! :-)
@Risu0chan
@Risu0chan 5 месяцев назад
My gcc compiler warns me against the use of %zu (expects a size_t type)
@yogeshchauhan9401
@yogeshchauhan9401 Год назад
Int arr[10]; Int *ptr; Is ptr=arr,ptr=&arr and ptr=&arr[0] same ?
@PortfolioCourses
@PortfolioCourses Год назад
No, arr and &arr are not the same, that's what's covered in this video. :-) If you have questions about what's in the video I can try to help explain, but the video discusses why arr and &arr are not the same.
@yogeshchauhan9401
@yogeshchauhan9401 Год назад
@@PortfolioCourses ya i saw it but like in below code #include int main(){ int arr[10]={1,2,3,4,5}; int *ptr=arr; *ptr++; printf("%d",*ptr); return 0; } It is printing 2 only i thought it will add 5×4=20 to the ptr.
@PortfolioCourses
@PortfolioCourses Год назад
I think that's a precedence thing, the operators have different precedence: www.tutorialspoint.com/cprogramming/c_operators_precedence.htm. So if you have: *ptr++; The ++ will work first, incrementing the pointer ptr to point to the next int. So instead of pointing to 1 it points to 2. The dereference * operator than happens afterwords, but it has no effect because it's just the value "2" but nothing is being done with it. Then on the next line when printf() is called, ptr has been set to point to '2' now so that is what is output. Hopefully this helps! :-)
@TheBlueconsole
@TheBlueconsole Год назад
Great video, but one thing is confusing to me. I know that array and &array don't refer to the same thing, but why does array == &array??? Correct me if I'm wrong but, array == &array is saying that the value of array is equal to its location in memory.
@PortfolioCourses
@PortfolioCourses Год назад
It's because the memory addresses are the same. array decays to a pointer to the first element of the array... i.e. the memory address of the first array element. &array gives us the pointer to the entire array, which is also going to be the memory address of the first element. So they compare equally because they have the same value, even though one is technically a pointer to the first element and one is technically a pointer to the entire array. Hopefully this helps! :-)
@TheBlueconsole
@TheBlueconsole Год назад
@@PortfolioCourses I think my confusion lies in the phrase "decays to a pointer". To my knowledge, the array will decay to a pointer when it's passed to a function. The function's stack frame will hold the array(address of first element) as a value in its respective parameter. But on its own the array is simply memory address, no?
@PortfolioCourses
@PortfolioCourses Год назад
Essentially yes, "array" is just a memory address, the memory address of the first element. But the way things behave sometimes depends on the context in which they are used. array[4] will give us the memory address of the 5th element in the array, for example.
@marsovac
@marsovac 5 месяцев назад
I would expect matrix[1] to point to the second row and matrix[1][0] to point to the first element of the second row of matrix. Why does matrix[1] decay to matrix[1][0] ? Doesn't seem logical since clearly the second element in matrix is a row, not a value inside that row.
@oneloveafrica8860
@oneloveafrica8860 4 месяца назад
we need the difference b/n p[] and *p
@NhatHuy-rp8hh
@NhatHuy-rp8hh Год назад
Word
@PortfolioCourses
@PortfolioCourses Год назад
Thank you! :-)
@gammyhorse
@gammyhorse Год назад
The pointer concept is not difficult. What makes it difficult to recognize what is what is the C syntax when it comes to pointers which is awful. Pointers are easy, the syntax is confusing.
@PortfolioCourses
@PortfolioCourses Год назад
I agree the syntax makes pointers more challenging than they need to be. 🙂 Lots of people have left comments on videos over the years saying the same thing too!
@barryday9352
@barryday9352 Год назад
It's called an address operator, not an and operator
@PortfolioCourses
@PortfolioCourses Год назад
Yes it is called the address operator, but it's not incorrect to refer to it as the & ("and") operator either. We do this all the time when talking about different operators, referring to the symbol used when talking about the operator.
@barryday9352
@barryday9352 Год назад
@@PortfolioCourses I disagree. The AND operator is a bitwise and logical operator. The name of an operator refers to the function it performs, not the name of the symbol used. Using incorrect names for operators just makes things confusing for people learning C
@PortfolioCourses
@PortfolioCourses Год назад
@@barryday9352 Learning that people call things different names is an important part of learning to program. 🙂 We call base classes in object oriented programming parent classes, super classes, etc, it's just part of being a programmer that there isn't always one "correct" way to say things. I try to stay consistent within my own videos, that's what a good resource should do, because ultimately there's going to be different words for the same thing. For example prominent C programming resources also call the & operator the "reference operator" too, which is probably coming from C++, or from * being referred to as the de-reference operator, but there's not much we can do about it. Bitwise and is one & and logical and is two &&s, those are two different operators technically. The important thing is to understand what it does, focusing on the terminology isn't important unless it's inaccurate, unclear or inconsistent, none of which apply to the way I'm using the word "and operator" in this video.
@Pabloparsil
@Pabloparsil 10 месяцев назад
I like C but this stuff was such a mistake
@PortfolioCourses
@PortfolioCourses 10 месяцев назад
I get a lot of comments like this on my videos, so I suspect your thoughts are widely shared. :-)
@Pabloparsil
@Pabloparsil 10 месяцев назад
@@PortfolioCourses Well even if C had some big mistakes your videos help a lot, thank you!
@PortfolioCourses
@PortfolioCourses 10 месяцев назад
You're welcome, I'm glad the videos are helpful! :-)
@sbk6768
@sbk6768 Год назад
I'm too later for tNice tutorials, I'll be back stoned...
@PortfolioCourses
@PortfolioCourses Год назад
OK sounds good, but I feel like this should be a joint decision!
@xboklx
@xboklx 5 месяцев назад
The all this sh*t is not because of a flexibility of C, but because of lack of definitivity. Pointer should be an address, and increasing of an antes should always increase an address by a byte, regardless the size of array element. Because pointer is an address, no metter what data it point at. So I assume it as a problem in C. Who is no accept it and has different vision - let’s discuss.
@fusca14tube
@fusca14tube 2 года назад
AWESOME!!!! Please, keep doing this kind of videos! Thank you!!!
@PortfolioCourses
@PortfolioCourses 2 года назад
You’re welcome Fabiano! I’m glad to hear you enjoyed it, if there are ever any topics your interested in seeing covered feel free to share them, and I can add them to my “video idea list”. :-)
@fusca14tube
@fusca14tube 2 года назад
@@PortfolioCourses Can you explain advanced topics related to Linux network?
@PortfolioCourses
@PortfolioCourses 2 года назад
@@fusca14tube When you say linux network, do you mean the terminal (shell) commands?
@fusca14tube
@fusca14tube 2 года назад
@@PortfolioCourses Hi... no... C programming. Being more specific, a Linux network event driven architecture, like demonstrated in "GH eileen-code4fun NginxEventLoop". I really want to understand this topic, but I know it's super advanced. Thanks.
@PortfolioCourses
@PortfolioCourses 2 года назад
@@fusca14tube Oh OK I understand now. I am hoping to do some more basic networking in the future, this one is more advanced for sure, but I've added to my list of future ideas. 🙂
Далее
Dynamic Memory Allocation | C Programming Tutorial
31:51
Прятки #nyanmp3
00:25
Просмотров 140 тыс.
Function Pointers | C Programming Tutorial
18:31
Просмотров 56 тыс.
Difference between arrays and pointers in C
11:23
Просмотров 31 тыс.
arrays are weird
6:57
Просмотров 104 тыс.
Pointer Notation | C Programming Tutorial
17:00
Просмотров 8 тыс.
Master Pointers in C:  10X Your C Coding!
14:12
Просмотров 287 тыс.
C Arrays and Pointers to Pointers
35:20
Просмотров 17 тыс.