array vs &array Pointers Difference Explained | C Programming Tutorial

  Рет қаралды 37,956

Portfolio Courses

Portfolio Courses

2 жыл бұрын

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!

Пікірлер: 151
@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! ❤
@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! :-)
@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
@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.
@armanlodhra7995
@armanlodhra7995 Жыл бұрын
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 Жыл бұрын
Thank you for the kind feedback Arman, I really appreciate that! 😀
@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!
@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! 🙂
@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! :-)
@christopheanfry2425
@christopheanfry2425 5 ай бұрын
I love your videos going full c and your videos help me so much to understand these tricky concepts. Thanks again 🙏
@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! :-)
@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! :-)
@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! 😀
@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
@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! :-)
@lisandroiaffar4501
@lisandroiaffar4501 5 ай бұрын
Excellent video, thank you so much!
@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. :-)
@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 2 ай бұрын
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.
@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! :-)
@Exoepxoe
@Exoepxoe 3 ай бұрын
amazing, thank you very much for this fantastic video.
@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! :-)
@user-yw8yy4qy3y
@user-yw8yy4qy3y 10 ай бұрын
very good explanation thanks for your helpful videos
@choppinbrixx4931
@choppinbrixx4931 11 ай бұрын
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
@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 5 күн бұрын
Thank you very much for this thorough explanation, you provided an invaluable insight, and I'm very grateful for it
@PortfolioCourses
@PortfolioCourses 5 күн бұрын
You’re very welcome! :-)
@Mnogojazyk
@Mnogojazyk Жыл бұрын
I’m glad I found your course and videos. But wonder I nearly failed C lo those many decades ago.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad you found them too! One of the better programmers I know failed introductory programming 3 times.
@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 11 күн бұрын
i mean this is what i was exactly looking for , thank u so much ❤
@PortfolioCourses
@PortfolioCourses 11 күн бұрын
You’re very welcome! :-)
@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. 🙂
@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! :-)
@tails_the_god
@tails_the_god Жыл бұрын
THANK YOU SIR!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! 😀
@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!
@fadieid5638
@fadieid5638 Жыл бұрын
Love it 😍
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad to hear you love it! :-D
@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! 🙂
@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?
@maorberenstein2540
@maorberenstein2540 Жыл бұрын
You are a god teacher man I love you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you for the love Maor! :-)
@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.
@cipherxen2
@cipherxen2 2 ай бұрын
There are very few concepts you need to understand to master pointers. Most important is understanding 'type of pointer'.
@CZghost
@CZghost 4 ай бұрын
So that's pretty much useful to calculate the size of the array.
@yclept9
@yclept9 7 ай бұрын
What about char *argv[]? Array of pointers to char with indefinite size.
@prakhartiwari7537
@prakhartiwari7537 Жыл бұрын
Great
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you Prakhar! :-)
@Risu0chan
@Risu0chan 5 ай бұрын
My gcc compiler warns me against the use of %zu (expects a size_t type)
@jawadikram5989
@jawadikram5989 Жыл бұрын
Let’s go!!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Haha I love the enthusiasm! :-)
@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. :-)
@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.
@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… 🤷🏻‍♀️
@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.
@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 "kzfaq.info/get/bejne/asVidaiYtKzIYHk.html" // Dynamically Allocate Memory For An Array Of Strings // very interesting too!
@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! :-)
@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: kzfaq.info/get/bejne/aN1-lpRmnpiaiGg.html
@dutta.alankar
@dutta.alankar 3 ай бұрын
@@PortfolioCourses Thanks for pointing out this video!
@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. :-)
@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: kzfaq.info/get/bejne/asVidaiYtKzIYHk.html.
@muhisaleh4598
@muhisaleh4598 Жыл бұрын
@@PortfolioCourses thank you very much 🙈😇
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@muhisaleh4598 You're welcome! 🙂
@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.
@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!
@oneloveafrica8860
@oneloveafrica8860 4 ай бұрын
we need the difference b/n p[] and *p
@NhatHuy-rp8hh
@NhatHuy-rp8hh Жыл бұрын
Word
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you! :-)
@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 Жыл бұрын
AWESOME!!!! Please, keep doing this kind of videos! Thank you!!!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
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 Жыл бұрын
@@PortfolioCourses Can you explain advanced topics related to Linux network?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@fusca14tube When you say linux network, do you mean the terminal (shell) commands?
@fusca14tube
@fusca14tube Жыл бұрын
@@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 Жыл бұрын
@@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. 🙂
function vs. &function Pointers | C Programming Tutorial
6:01
Portfolio Courses
Рет қаралды 8 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 78 М.
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 36 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 63 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 287 М.
Difference between arrays and pointers in C
11:23
CodeVault
Рет қаралды 31 М.
C pointers explained👉
8:04
Bro Code
Рет қаралды 149 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 56 М.
arrays are weird
6:57
Low Level Learning
Рет қаралды 104 М.
C Arrays and Pointers to Pointers
35:20
Kris Jordan
Рет қаралды 17 М.
Dynamically Allocate An Array Of Structs | C Programming Tutorial
15:11
Portfolio Courses
Рет қаралды 33 М.
Pointer Notation | C Programming Tutorial
17:00
Portfolio Courses
Рет қаралды 8 М.
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН