array vs &array Pointers Difference Explained | C Programming Tutorial

Поделиться
HTML-код
  • Опубликовано: 23 июл 2022
  • 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!

Комментарии • 153

  • @thanostzia
    @thanostzia 6 месяцев назад +28

    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.

  • @succerzxix1950
    @succerzxix1950 7 месяцев назад +30

    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! ❤

  • @infas_mhd
    @infas_mhd Год назад +15

    Every small detail about c is crystal clear here in this channel..Keep it up bro...

    • @PortfolioCourses
      @PortfolioCourses  Год назад +1

      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.

  • @avixx
    @avixx 2 месяца назад +1

    Your programming language tutorials are one of best on YT, amazing job!

  • @justwalk7063
    @justwalk7063 Год назад +13

    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  Год назад +3

      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 Год назад +1

      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 года назад +30

    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 года назад +2

      Thank you for the kind feedback Arman, I really appreciate that! 😀

  • @marcellogambetti9458
    @marcellogambetti9458 3 месяца назад +1

    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 Год назад +13

    Mr. all of your videos are 100% understandable unlike lecturers at my university. well done !

    • @PortfolioCourses
      @PortfolioCourses  Год назад +2

      Thank you very much for the positive feedback, I'm really glad to hear you're finding the videos understandable. 🙂

    • @duldulatori3123
      @duldulatori3123 Год назад +2

      ​@@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! 🙂

  • @christopheanfry2425
    @christopheanfry2425 6 месяцев назад +1

    I love your videos going full c and your videos help me so much to understand these tricky concepts. Thanks again 🙏

  • @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.

  • @kitchenchem141
    @kitchenchem141 Год назад +2

    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 Год назад +1

    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! :-)

  • @CuriousCyclist
    @CuriousCyclist Год назад +1

    These videos deserve a lot more views. They are really good. Thanks.

    • @PortfolioCourses
      @PortfolioCourses  Год назад +1

      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. :-)

  • @nameless5724
    @nameless5724 2 года назад +2

    AWESOME!!!! Please, keep doing this kind of videos! Thank you!!!

  • @mohammedal-twaity7521
    @mohammedal-twaity7521 Год назад +7

    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.

  • @vadimgerasimenko4904
    @vadimgerasimenko4904 2 месяца назад

    Thank you for sharing knowledges and source code!

  • @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! :-)

  • @fifaham
    @fifaham Год назад +2

    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.

  • @hansdampf2284
    @hansdampf2284 3 месяца назад

    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

  • @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  Год назад

      You're very welcome, I'm glad the video helped make it click! :-D

  • @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! :-)

  • @selimsagr446
    @selimsagr446 2 года назад +1

    All videos are great! But this one solved one of the problem I struggle to understand always :) Thanks.

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      That's awesome, glad to hear that Selim, and you're welcome! 😀

  • @Rafael-fp9xc
    @Rafael-fp9xc 6 месяцев назад +2

    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.

  • @Guidoev2
    @Guidoev2 25 дней назад

    Thank you very much for this thorough explanation, you provided an invaluable insight, and I'm very grateful for it

  • @Mnogojazyk
    @Mnogojazyk 2 года назад +2

    I’m glad I found your course and videos. But wonder I nearly failed C lo those many decades ago.

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +3

      I’m glad you found them too! One of the better programmers I know failed introductory programming 3 times.

  • @lisandroiaffar4501
    @lisandroiaffar4501 6 месяцев назад

    Excellent video, thank you so much!

  • @ሰውመሆን
    @ሰውመሆን Год назад

    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.

  • @Exoepxoe
    @Exoepxoe 3 месяца назад

    amazing, thank you very much for this fantastic video.

  • @user-yw8yy4qy3y
    @user-yw8yy4qy3y 10 месяцев назад

    very good explanation thanks for your helpful videos

  • @dimitrioskalfakis
    @dimitrioskalfakis Год назад

    good and useful points. nice clean method of presenting essential topics.

  • @sravanakumar9326
    @sravanakumar9326 Год назад

    Wow, such a great explanation 🎉

  • @1nonly_user
    @1nonly_user Месяц назад

    i mean this is what i was exactly looking for , thank u so much ❤

  • @khomo12
    @khomo12 4 месяца назад

    Nice!👍👍👍

  • @walidoulondon8107
    @walidoulondon8107 5 месяцев назад

    This guy is a legend greeting from England ❤

  • @fadieid5638
    @fadieid5638 2 года назад

    Love it 😍

  • @matheuslbatista
    @matheuslbatista Год назад

    Great video! Thanks!

    • @PortfolioCourses
      @PortfolioCourses  Год назад +1

      You’re welcome Matheus, I’m glad you enjoyed it! :-)

    • @matheuslbatista
      @matheuslbatista Год назад

      @@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  Год назад

      @@matheuslbatista 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 5 месяцев назад +1

    terrific instructor

    • @PortfolioCourses
      @PortfolioCourses  5 месяцев назад +1

      I'm glad you're enjoying the teaching! :-)

  • @tails_the_god
    @tails_the_god Год назад

    THANK YOU SIR!

  • @Abake-117
    @Abake-117 4 месяца назад

    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!

  • @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 🙃🙃.

  • @tornado-zex47
    @tornado-zex47 Год назад

    best of luck keep going

  • @cipherxen2
    @cipherxen2 3 месяца назад

    There are very few concepts you need to understand to master pointers.
    Most important is understanding 'type of pointer'.

  • @hlubradio2318
    @hlubradio2318 4 месяца назад

    Wow will I ever need to use it?

  • @CZghost
    @CZghost 5 месяцев назад

    So that's pretty much useful to calculate the size of the array.

  • @maorberenstein2540
    @maorberenstein2540 Год назад

    You are a god teacher man I love 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. :-)

  • @vicsteiner
    @vicsteiner 17 дней назад

    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.

  • @jawadikram5989
    @jawadikram5989 2 года назад

    Let’s go!!!

  • @Risu0chan
    @Risu0chan 6 месяцев назад

    My gcc compiler warns me against the use of %zu (expects a size_t type)

  • @yclept9
    @yclept9 8 месяцев назад

    What about char *argv[]? Array of pointers to char with indefinite size.

  • @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.

  • @goktugparlak1618
    @goktugparlak1618 Год назад +1

    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. :-)

  • @emerior-x-brawlstars551
    @emerior-x-brawlstars551 2 года назад

    ti (the instrunt into the channel rack) and then it crashes the soft soft... Can soone help please?

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      I'm not sure what you're asking, maybe someone else can help.

  • @06watta
    @06watta 2 года назад

    Hey man quick question what IDE do you use I see a lot of youtubers use it.

  • @prakhartiwari7537
    @prakhartiwari7537 2 года назад

    Great

  • @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  Год назад +1

      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  Год назад +1

      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… 🤷🏻‍♀️

  • @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 месяца назад +1

      sizeof() is not a function, it’s an operator: ruclips.net/video/2wNc15926X4/видео.html

    • @dutta.alankar
      @dutta.alankar 3 месяца назад

      @@PortfolioCourses Thanks for pointing out this video!

  • @alphonsereitz
    @alphonsereitz 3 дня назад

    I'll be watching this multiple times.. I'm having such trouble with an spi function taking a const uint16_t *in..
    Ptrs themselves aren't bad, but arrays for some reason still woosh over my head.

  • @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  Год назад +1

      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 "ruclips.net/video/4_2BEgOFd0E/видео.html" // Dynamically Allocate Memory For An Array Of Strings // very interesting too!

  • @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  Год назад +1

      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: ruclips.net/video/4_2BEgOFd0E/видео.html.

    • @muhisaleh4598
      @muhisaleh4598 Год назад

      @@PortfolioCourses thank you very much 🙈😇

    • @PortfolioCourses
      @PortfolioCourses  Год назад

      @@muhisaleh4598 You're welcome! 🙂

  • @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 Год назад +1

      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  Год назад +2

      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! :-)

  • @marsovac
    @marsovac 6 месяцев назад +1

    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.

  • @yogeshchauhan9401
    @yogeshchauhan9401 Год назад +1

    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  Год назад +1

      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! :-)

  • @gammyhorse
    @gammyhorse Год назад +2

    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  Год назад +1

      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

  • @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  Год назад +1

      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.

  • @NhatHuy-rp8hh
    @NhatHuy-rp8hh 2 года назад

    Word

  • @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 11 месяцев назад

    I like C but this stuff was such a mistake

    • @PortfolioCourses
      @PortfolioCourses  11 месяцев назад +1

      I get a lot of comments like this on my videos, so I suspect your thoughts are widely shared. :-)

    • @Pabloparsil
      @Pabloparsil 11 месяцев назад

      @@PortfolioCourses Well even if C had some big mistakes your videos help a lot, thank you!

    • @PortfolioCourses
      @PortfolioCourses  11 месяцев назад

      You're welcome, I'm glad the videos are helpful! :-)

  • @sbk6768
    @sbk6768 2 года назад

    I'm too later for tNice tutorials, I'll be back stoned...

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      OK sounds good, but I feel like this should be a joint decision!

  • @xboklx
    @xboklx 6 месяцев назад

    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 года назад +1

    AWESOME!!!! Please, keep doing this kind of videos! Thank you!!!

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      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 года назад +1

      @@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. 🙂