Pointers and 2-D arrays

Sdílet
Vložit
  • čas přidán 6. 09. 2013
  • See complete series on pointers here:
    • Pointers in C/C++
    In this lesson, we will see how we can work with 2-D (two dimensional) arrays using pointers. We have explained how 2-D arrays are organized in memory and how pointer arithmetic and dereferencing can be used to work with 2-D arrays.
    For more such videos and updates, you may subscribe to our channel.
    For practice problems and more, visit: www.mycodeschool.com
    Like us on Facebook: / mycodeschool
    Follow us on twitter: / mycodeschool

Komentáře • 307

  • @Phoenix01914
    @Phoenix01914 Před 3 lety +130

    Indians came from another planet, thank you very much for the awesome explanation. Greetings from Italy!

    • @anabeatriz8835
      @anabeatriz8835 Před 3 lety +38

      Indians that are educators yes, Indians that are on tiktok no

    • @dharaniidharkatikaneni4973
      @dharaniidharkatikaneni4973 Před 3 lety +3

      @@anabeatriz8835 yeah

    • @satyamrajput825
      @satyamrajput825 Před 3 lety +2

      But in everfield indian always beat other

    • @Phoenix01914
      @Phoenix01914 Před 3 lety +9

      @@satyamrajput825 Each nation has its excellences but remeber, none is better than the others. Your thought remind me some little man living in Germany some years ago..

    • @satyamrajput825
      @satyamrajput825 Před 3 lety +1

      @@Phoenix01914 yeah ! i agree with your thoughts but it is not a good thing to condemn anyone's

  • @KishanKumar-mz3xr
    @KishanKumar-mz3xr Před 5 lety +181

    Thanks for watching. I mean why?
    .
    .
    .
    THANKS FOR MAKING bruh

  • @AbhimanyuAryan
    @AbhimanyuAryan Před 10 lety +116

    *_i really loved this video. This video was so conceptual i have seen lots of C video playlists on youtube but none of the video covered such details. I really admire the effort you made and you are really good programmer :) hope i get to learn java from you_*

    • @Boltkiller96
      @Boltkiller96 Před 2 měsíci

      hey 9 years have passed look at your comment

  • @jeffflammer9606
    @jeffflammer9606 Před 7 lety +54

    I have done a lot of online courses included Strang's (MIT) Linear Algebra, Khan Academy, and Noam Nissan's Nand2Tetris. Not sure of the instructors name, but mycondeschool teaches with the same clarity and intuition of these other great instructors.

    • @anshuman17025
      @anshuman17025 Před 6 lety +16

      Nope, he is from IIIT-Allahabad, not from any IIT. It is only because of his own dedication that he has reached this level of clarity, and not because of his college or anything. Here he is: www.linkedin.com/in/animesh-nayan-0a330812/

  • @michaelpatterson1096
    @michaelpatterson1096 Před rokem +8

    Had to watch the video 3 times! :) Hopefully I can explain this correctly. At 4:30 in the video, pay attention. If B were a 1d array, then B[0]=200. Then, using * to dereference gives you '2'. If however, B is a 2d array, then once again B[0] = 200 BUT of a 2d array which means when you dereference with *, you are still at 200 but, now in a 1d array! Confused? Watch it over and over like I did. In other words, to print '2' when B is a 2d array, , use **B. This was fouling me up. Got it now. Thank you.

  • @lautarodelucia6480
    @lautarodelucia6480 Před 6 lety +6

    After about 12 straight hours of scratching my head with pointer exercises, all the answers I needed were in this video. Eternally grateful to you!

  • @ulysses_grant
    @ulysses_grant Před 6 lety +2

    You NAILED it! This is the BEST class of Pointers and 2-D arrasys I've ever seen. FOR GOOD. Thank you so much!!

  • @shashankkhemka1444
    @shashankkhemka1444 Před 7 lety +6

    This is the best explanation that I have seen so far for this topic. You are really amazing !!

  • @bukubukuchakama6005
    @bukubukuchakama6005 Před 4 lety +4

    This was the best tutorial video on pointers for multi-dimentional array that I have ever watched. Thank you so much for making such tutorial videos,it helps us a lot. Thankyou very much

  • @SuperTurkce
    @SuperTurkce Před 7 lety +5

    Explained really beautifully! Thanks for allocating your time for creating this series of lectures.

  • @pengpeng991
    @pengpeng991 Před 7 lety +8

    good job!!!! you know i can't understand C pointer and some other things about data structures and algorithms ,before watching these videos ! you are the best ! thank you so much ! ---you fans from China

  • @huysaysoui
    @huysaysoui Před 10 měsíci +2

    I can’t believe you describe such a complex concepts in this way. Good channel, i will see you a lots

  • @AmrMouhamed
    @AmrMouhamed Před 4 lety +4

    omg I love you sir 😂❤
    I've been looking for this explaination for literally months and never understood how to handle 2D arrays with pointers untill I saw this video
    thank you so much for making this video ❤❤

  • @shivagameon
    @shivagameon Před 8 lety

    superb video series , none I have seen that clears concepts in pointers this deep and lucidly.

  • @mycodeschool
    @mycodeschool  Před 10 lety +6

    Hi Raj ,
    We have a lot of requests for videos on these areas and we definitely want to cover them soon. We currently have only one mentor creating videos and things are slow. We are trying to speed up by pulling in more contribution. Sorry to keep you waiting , but these videos are promised and are high in our priority.

  • @midrangeshot8203
    @midrangeshot8203 Před 2 lety +4

    It helped me to think about these examples by using the word adress. Also, that part in the begining of the video it is shown that in 1D array B[1] == *(B+1) and
    &B[1] == B+1. It helped me to think about multi dimensional arrays as things, where the previous two rules apply. Also, keep in mind that if you have a 2D array like in this video B[2][3], if you write B[0] that is a 1D array (1D array which has 3 elements in it). Which means that B[0] is a memory adress. These three insights (or four depending on how you count them) were what made me understand this. Hope this helps to someone struggling to understand this. If you don't get it immediately, watch the video again, think about it and you will understand it.

  • @travellingsLenses
    @travellingsLenses Před 6 lety +1

    One of the best stuff available on the internet. :) Keep it up.

  • @ianchandra4107
    @ianchandra4107 Před 2 lety

    Usually hate scouring for coding videos on youtube cause they all suck, but this video really helped! Came into this with a lot of scepticism, but was shocked with how he dumbed everything down to make it understandable (unlike my prof). Thanks for making this video bro, cleared up alot of questions.

  • @amizan8653
    @amizan8653 Před 8 lety +2

    This video was infinitely helpful, thanks for posting!

  • @wsmao1154
    @wsmao1154 Před 7 lety +2

    it's the best tutorial that i've heard
    thanks for all effort you made !

  • @waleedosama1630
    @waleedosama1630 Před 7 lety

    i can not find someone bettr than you in anything you explain ... you are awesome ...keep up the good work ..thanks

  • @14JINU14
    @14JINU14 Před 10 lety

    Excellent walk-through. Well explained with very good examples. Thank you so much.

  • @jupiterscreams
    @jupiterscreams Před 8 lety +2

    Thank you for this tutorial. Very easy to understand!

  • @chennayaianjc3306
    @chennayaianjc3306 Před 3 lety

    A best teacher, explains clearly in one single line,

  • @raunakmaheshwari2034
    @raunakmaheshwari2034 Před 7 lety +27

    To all those who have a doubt that at why 8:29, (B+1) and *(B+1) both are equal to 412, here is the answer.
    B+1 gives the address of a pointer which is pointing to a 1-D array of size 3. The type of the pointer is such that it points to a 1-D array and in this particular case it is pointing to the 2nd element of the 2-D array, that is, row B[1]. So when you do pointer arithmetic, it will increment or decrement with the size of a 1-D array of size 3. For example, B+2 will give the address of a pointer of the next row in the 2-D matrix, that is, address of B[2].
    On the other hand, *(B+1) is a type of an integer pointer which points to the first element of the 1-D array. This is an integer pointer and arithmetic on this would result in increment and decrement with the size of an integer, that is, 4 bytes. Hence *(B+1) +1 would give the address of the next integer!

    • @mnkshk
      @mnkshk Před 6 lety

      thanks

    • @Aditya-us5gj
      @Aditya-us5gj Před 5 lety

      Thanks man ! that was helpful

    • @Mangosrllysuck
      @Mangosrllysuck Před 4 lety +1

      So it just so happens that the address of the pointer to second subarray (B+1) is the SAME as the address of the first element of second subarray *(B+1), am I correct?

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      @Mangosrllysuck That's what bugs me as well about his comment. Here's how I understood this video. Let's see what *(B+1) + 1 is.
      *(B+1) is the same as B[1]. So, we get B[1] + 1.
      We know that B[1] is itself a 1D array.
      B[1] is therefore the memory adress of that 1D array (elements of the array that I am talking about are B[1][0], B[1][1], B[1][2]).
      So, B[1] + 1 is the same thing as &(B[1][1]).
      It is the memory adress of B[1][1]. In other words, it is the number 416.

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      @@Mangosrllysuck Did I get it right, is *(B + 1) + 1 equal to 416?

  • @Shaddad_Gomid
    @Shaddad_Gomid Před 5 lety +2

    Thanks a lot, the most informative and to-the-point video about this subject

  • @SmartProgramming
    @SmartProgramming Před 6 lety

    very helpful video sir, the way you have explained is really appreciating, thank you 👍👍

  • @mycodeschool
    @mycodeschool  Před 10 lety +17

    Please watch the video "Pointers and arrays" in this series. It will help you understand the concept.

    • @chennayaianjc3306
      @chennayaianjc3306 Před 3 lety +1

      Please man come on and do more videos on data structures and interview questions , that make our lives good

    • @peterpace3379
      @peterpace3379 Před 3 lety +1

      You should really consider coming back to this channel brother. We need you!

  • @ahmeddeiaa3943
    @ahmeddeiaa3943 Před 6 lety +2

    this tutorial is quite amazing. Thank you and please keep it up

  • @225mrraj
    @225mrraj Před 10 lety +1

    u r simply the BEST on youtube.!!

  • @munbee_
    @munbee_ Před 6 lety +1

    Every other videos where great, except this one.. i had to watch it 4-5 times (the part which starts explains 2d array) over to get the pont. anyway, i'm very much thankful that it helped me understand somewhat.

  • @user-or7ji5hv8y
    @user-or7ji5hv8y Před 5 lety

    you are really a great teacher! such lucid explanation.

  • @siishasha2176
    @siishasha2176 Před 4 lety

    You are an Angel! Thank you so much for all these amazing videos!

  • @rishabh6051
    @rishabh6051 Před 3 lety

    thanks for making this video, I was very struggling with pointer to array. You have explained very well

  • @minatorman5047
    @minatorman5047 Před 4 lety +35

    b+1 gives 412 !! *(b+1) should gives the value stored in that particuler address why it gives an addresss ??

    • @abdimalikosman559
      @abdimalikosman559 Před 4 lety +5

      That is what i was thinking too.

    • @vaneetgupta7189
      @vaneetgupta7189 Před 4 lety +11

      print *(b+1) is same as
      print b[1] where b[1][3]={4,5,6}
      think of it as
      Print A where A[3]={4,5,6}
      this will print the address of the first element of A[3].

    • @charansashidhar2214
      @charansashidhar2214 Před 4 lety

      @@vaneetgupta7189 what is *B

    • @balaganesh3440
      @balaganesh3440 Před 4 lety +11

      @@charansashidhar2214
      *B returns the initial address of the first element in the first row of the multi dim array. In this case, B and *B are the same, since both represent the address of the initial element of the whole multi dim array which is nothing but the first element in the first row.
      When we dig into the multi dim array,
      say, B[0] returns the address of the first element of the initial row, *B[0] returns the value at the first element of the initial row.
      B[1] returns the address of the first element of the second row, *B[1] returns the value at the first element of the second row.
      When we still dig deeper we get the values,
      say, B[0][0] returns the value of the first element in the first row.
      Don't get confused about the following,
      internally the array works in the way when we get B[1][1] ,
      *(*B[1] + 1) //this is the structure of the element B[1][1]
      => *(&B[1][1]) // returns the address of B[1][1] which is then dereferenced to get the value.
      => B[1][1] // C provides an easy way to access the elements directly from this step by ignoring the above steps
      => value at B[1][1]

    • @saimanognanelavelli8005
      @saimanognanelavelli8005 Před 3 lety +4

      This is actually explained in some previous video , when they talk about generic pointer and why the pointers have types
      like int *p1;char *p2 ......
      Because we can dereference them later and for that we need to know what exactly lies at address 412, is it an int ? (no) there is an array B[1] stored at 412 .
      Now 412 is actually address of an array B[1] (let B[1]=A)
      so the statement printf( *(B+1) )=printf( B[1] )=Printf(A) which gives base address/address of first value ( A[0] or B[1][0])
      hope it helps :)

  • @shadabahmed4547
    @shadabahmed4547 Před 4 lety +1

    sir really you have very deep knowlege.My concepts are cleared so much ,now i have to just apply it in real code

  • @MrViney333
    @MrViney333 Před 8 lety

    @mycodeschool Thanks to you pointers is clear to me. Thank you very much

  • @03Karthikeyan
    @03Karthikeyan Před 8 lety

    Thanks man! I had to listen to this couple of times, but it made sense.

  • @btcblade3334
    @btcblade3334 Před 7 lety

    bro your videos are so good and concise

  • @jonvonnoobman2823
    @jonvonnoobman2823 Před 2 lety +1

    Dude, u rock! U explain stuff much better than IIT profs. And yeah, this is coming from an IIT fresher.

  • @ShopperPlug
    @ShopperPlug Před 2 lety

    Holy cow, this is another realm of C programming and can write pointer codes my ways. I would never be able to figure out how all of the advanced pointer code works without understanding the fundamentals.

  • @mycodeschool
    @mycodeschool  Před 10 lety +13

    Thanks Adamou :)

  • @moony1926
    @moony1926 Před 4 lety

    Super super helpful and clear! Thank you so much!

  • @AffaAu
    @AffaAu Před 4 lety

    Great effort, great explanation. Thanks.

  • @deepeshshrestha1036
    @deepeshshrestha1036 Před 2 lety +1

    This is cool 🌊 . I still haven't grasped the concept the way 2D array name makes partition to the memory but if that foundation is pre-set by law(law of C language 😝) Then you have my gratitude brother. I got this.❤️

  • @priyasukumaran
    @priyasukumaran Před 4 lety +1

    Sir.. you doing a great job.. thank you so much..!!

  • @drcvagos-iu
    @drcvagos-iu Před 9 lety

    thank you for these tutorials!

  • @roshaniguthe7983
    @roshaniguthe7983 Před 7 lety

    very good lecture....specially memory allocation topic is very nicely explain

  • @johnparks6936
    @johnparks6936 Před 8 lety +24

    Does anyone here understand why (b+1) and *(b+1) both produce 412? If you dereference shouldn't it produce the contents of 412 which is 4?

    • @Abhi94manyu
      @Abhi94manyu Před 8 lety

      Exactly my doubt

    • @johnparks6936
      @johnparks6936 Před 8 lety +1

      Abhimanyu Bhardwaj Yea, I still can't understand. Hopefully someone will help us.

    • @shishupal0iitb87
      @shishupal0iitb87 Před 7 lety +43

      did u get the answer to your doubt? i think its because :
      Thinking that 2-D array is an array of arrays,* (B+1) or B[1] should get you to second array (Second Row) which is an array instead of int element. And when array is assigned to something its the address of first element that gets assigned. So de-referencing it only once gets you the starting address of second array. De-referencing it again should get you the 4 ie **(B+1)=4. hope that makes sense

    • @pandalover555
      @pandalover555 Před 7 lety +1

      That makes so much sense - thank you!

    • @_kahini
      @_kahini Před 7 lety

      +Shishupal is **(B+1) and *(*B+1) the same or u made a mistake ?

  • @mycodeschool
    @mycodeschool  Před 10 lety +2

    &B is address of 2-D array , B is address of first 1-D array in the 2-D array , *B or B[0] is address of first integer in first 1-D array. All of these start at same address. &B[0][0] means address of B[0][0].. once again its the same.. the objects are different in size but their starting address is same. Feel free to ping back if still confused.

    • @buradaleelaprasanna5131
      @buradaleelaprasanna5131 Před 4 lety

      Sir *B means dereferencing then how it could be &B[0][0]

    • @zezo22abc
      @zezo22abc Před 4 lety

      how B[0][0] and &B[0][0] the same the 1st give me the value and 2nd give me the address

    • @tunamusic2314
      @tunamusic2314 Před 4 lety

      @@buradaleelaprasanna5131 *B or B[0] is address of first integer in first 1-D array. -> it is right ( you can watch previous video about it)
      &B[0][0] you can split it -> ( & and B[0][0] ) means B[0][0] is the first element of 1-D array so after add " &" , we have adress of the first element of 1-D array

  • @gokuafrica
    @gokuafrica Před 9 lety +1

    finally got it. Thank you!!!!!!

  • @Rakeshrajeev94
    @Rakeshrajeev94 Před 5 lety

    Very much helpful. Thanks team 😊

  • @theadel8591
    @theadel8591 Před 2 lety

    excellent explanation, not a strightforward concept (pointers of 2-D arrays) but manageable with some practice !

  • @sahilkanojia2531
    @sahilkanojia2531 Před 7 lety

    sir, I will understand good from your excellent explaination thank you so much

  • @gianniskurgiakis739
    @gianniskurgiakis739 Před 4 lety +2

    The B[0] = &B[0][0] part in this video is so good that it helped me click something I didn't understand all semester. Thanks for the video!

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety +2

      Exactly! B[0] is itself an array and when you just put the name of an array, that's the memory adress of the first element of the array. I think I got this, and if I did, then it clicked to me for the same reason that it clicked for you.

    • @happyteen7195
      @happyteen7195 Před 2 lety +1

      B[0] = &B[0] = &B[0][0] = B = &B = *B all gives same thing i,e same address

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      ​@@happyteen7195 Yes, B[0] gives you the first element of the outer array, which is itself an array, so you get the address of that array. So B=B[0]
      But then the address of the array B[0] is the address of the first element of the array, which means
      B = B[0] = &B[0][0].
      Then, we also know that *B is the same thing as B[0], so
      B = B* = B[0] = &B[0][0]
      Then we know that &B = B because the address of the array = array.
      &B = B = *B = B[0] = &B[0][0].
      I don't know why he didn't write code as an example. I will give you the actual code in the end of the comment.
      The other way to look at it is this, if we write &B, we get a 3D array whose first element is B, so if we print the that 3D array we will get the address of its first element which is B, and address of B is the address of its first element - B[0], and B[0] is also an array, so the address of B[0] is the address of B[0][0]. Basically, we are talking about the address of B[0][0] all the time.
      #include
      int main(){
      int B[2][3] = {{0,1,2}, {3,4,5}};
      printf(" B = %lld
      ", B);
      printf(" &B[0] = %lld
      ", &B[0]);
      printf(" B[0] = %lld
      ", B[0]);
      printf(" &B = %lld
      ", &B);
      printf("
      ");
      int A[4] = {1, 2, 3, 4};
      printf("A = %lld
      ", A);
      printf("&A = %lld
      ", &A);
      return 0;
      }

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      @@happyteen7195 Here is a video which explains this with code czcams.com/video/falKBQVWSLw/video.html

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      @@happyteen7195 Another important thing to say, and I am saying this while hoping that this will not just confuse you more, is that if you write
      int (*b)[3] = B;
      computer will treat b and B differently. In what sense? In a sense that if you write &b, computer will treat that as a double pointer, as an address of b. It will treat b as int** [3].
      On the other hand, if you write &B, computer will treat &B as a pointer to a 3D array whose first element is B. Computer will treat &B as int* [2][3].
      In other words B is equal to &B, but
      &b is not equal to b.
      Here is a program for you to check out on your own, I wanted these warning signs intentionally btw so that compiler tells us what types B, &B, b, &b etc. are
      #include
      int main(){
      int B[2][3] = {{0,1,2}, {3,4,5}};
      printf(" B = %lld
      ", B);
      printf(" &B[0] = %lld
      ", &B[0]);
      printf(" B[0] = %lld
      ", B[0]);
      printf(" &B = %lld
      ", &B);
      printf("
      ");
      int A[4] = {1, 2, 3, 4};
      printf("A = %lld
      ", A);
      printf("&A = %lld
      ", &A);
      printf("
      ");
      int* a = A;
      printf("a = %lld
      ", a);
      printf("&a = %lld
      ", &a);
      printf("
      ");
      int (*b)[3] = B;
      printf("b = %lld
      ", b);
      printf("&b = %lld
      ", &b);
      return 0;
      }

  • @Xardas_
    @Xardas_ Před 2 lety

    Pointers are no longer over my head. Thanks a lot !

  • @TheMateyl
    @TheMateyl Před 6 lety +2

    great explanation

  • @calvindennis6740
    @calvindennis6740 Před 6 lety

    Thank you! It helps a lot!

  • @farezuanruzlan292
    @farezuanruzlan292 Před 8 lety +1

    +mycodeschool is it the same case for 2d array of strings?

  • @notepad800
    @notepad800 Před 7 lety

    If i take the expression *(*p + k) and loop it from k = 0 to k = i*j - 1, I am scanning the entire 2-D array. So isnt this a better way to access 2-D arrays as it takes O(n) time compared to the other way which takes O(n^2)??

  • @kautukraj
    @kautukraj Před 4 lety +2

    Very helpful.

  • @dharmikmistry8781
    @dharmikmistry8781 Před 3 lety

    Thanks for your great efforts 🔥🔥😍🤗

  • @jeromyclassyca7063
    @jeromyclassyca7063 Před 2 lety

    This is the only lesson I found difficult that this man taught

  • @pedroantoniodesouzasilva2068

    Thank you very much, my friend!

  • @shiwangiagrawal8549
    @shiwangiagrawal8549 Před 6 lety

    Very good video. Thanku soo much. Helped a lot.😊😊

  • @dzzzzzt
    @dzzzzzt Před 9 lety +3

    A very eloquent way to present the topic. Hopefully many people will benefit from this. I certainly did for which I'm thankful.
    I'd appreciate if there was also an explanation as to why a pointer to an array of pointers has to be declared as int (*p)[3] although it may be a more advanced topic. Why can't int **p work? It is seen on the picture but not explained in full detail, i.e. the multidimensional array is located continuously in memory. So because of that in pointer arithmetic advancing the pointer with 1 must not move it by one byte (as if it were int **p) but by three (because of int (*p)[3]). int (*p)[3] literally means "a pointer to an array of three integers". int p[3] means that p is an array of 3 integers. Adding the asterisk makes p a pointer to an array of 3 integers, which is equivalent to the definition that the name of the array is a pointer to its first element.

    • @baltatuandrei3836
      @baltatuandrei3836 Před 8 lety +2

      +simich you have to know how to handle an expression .This links will help you c-faq.com/decl/spiral.anderson.html . This way you can see how the compiler looks and interprets an expression. (*p)[3] it states that p is a pointer to an array with 3 elements.
      It is because of array decaying. Whenever you assign a x-dimensional static declared array to a pointer,one dimension is lost(in the example (*p)[3]=B is really like (*p)[3]=&B[0],and &B[0] is an address to an array of 3 elements). You could ask,of,so I could do *p =&B[0] cuz I know I can do p=a where a is 1d array. But the compiler won't let you do this.
      At compile time it that B[0] has 3 elements ,and wants you to pass a pointer to 3 elements.
      What I'm saying about array decay,you see that (*p)[3] know there are 3 elements on a row,but doesn't know how many rows there are.
      You should really read a lot of topics on these ,it's not easy and it's tricky.
      All I say is this. Arrays are not pointers and pointers are not arrays.Even if you can do *pointer and *array,and you can pass an array to a pointer,deep down they aren't the same.At compile time you know the sizeof static declared array,but you can't know the size of what the pointer points to just until run-time,so it has some loss when passing as parameter.

  • @karimshaikh3900
    @karimshaikh3900 Před 3 lety

    Very well explained!

  • @vivekd4278
    @vivekd4278 Před 4 lety

    Nice explanation!

  • @adelleshob3660
    @adelleshob3660 Před rokem

    Thank you so much you solved my problem !!

  • @shikharchandra3028
    @shikharchandra3028 Před 8 lety +26

    @mycodeschool shouldn't * print the value instead of address? Please clarify

    • @_kahini
      @_kahini Před 7 lety +8

      in 2D array to get the value of that particular address you have to write *(*c+i) for example coz * is just a pointer to an integer

    • @adstub
      @adstub Před 7 lety +19

      See try to see it this way there is an array inside an array so the first time it is only going to give the address of the array and then we are going for the address of the variable name of the one dimensional array.

    • @midrangeshot8203
      @midrangeshot8203 Před 2 lety

      But the value of B[0] is an array, and arrays are represented as a memory adress of their first element.

  • @1qaribullah
    @1qaribullah Před 7 lety +1

    Great explanation... No need to study books. Thumb up..!!!!!!!!

  • @CylinderHead1
    @CylinderHead1 Před 9 lety +1

    What he says is totally right , it is in fact a little different than a 1D array. Just try it in your compiler and you'll see !

  • @snv1996
    @snv1996 Před 4 lety

    An excellent video mate! I dont know what your profession is But you should definitely teach in universities!! Thanks a lot from behalf of all the programmers you helped! (including me)

  • @ChekuriKavitha
    @ChekuriKavitha Před 5 měsíci

    A very good explanation on pointers. Plz give answer for *(B+1)[0]

  • @225mrraj
    @225mrraj Před 10 lety +1

    can u guide us more on stacks ,queues,trees n other stuff. on data structurea.

  • @cokpot635
    @cokpot635 Před 10 lety +20

    Why is it in 8.29, the *(B+1) or B[1] or &B[1][0] is equal to 412 ?
    I thought it would be 4.

    • @gautam9339513131
      @gautam9339513131 Před 9 lety

      Hi do knw the ans now ???

    • @mayukh_
      @mayukh_ Před 9 lety +2

      No to get 4, you have to write **(B + 1) or 0[1[B]]

    • @garryharry1024
      @garryharry1024 Před 8 lety +7

      +Nafiz Farhan Hey Nafiz. Let's break down *(B+1). First let's take a look at B. B is a 1-D array of three integers. In other words, B is simply the name of that 1-D array consisting of three integers. So therefore, it would give you a pointer to this 1-D array of three integers. Now if you increment B (since the type of B is a pointer to an array of three integers) it will increment B by 12 (since 3*4 = 12 bytes). Now B is pointing to the second array of three integers. Which is the same as B[1]. Now (B+1) combined gives you the pointer to the second array of three integers. Now if you dereference that it would give you the address of the first integer in that second 1-D array which is 412.

    • @probhakarsarkar2430
      @probhakarsarkar2430 Před 7 lety

      wrong

    • @probhakarsarkar2430
      @probhakarsarkar2430 Před 7 lety

      I think like that: B[i] is a pointer to the pointer &B[i][j] i.e. B[0] is the pointer to the pointer &B[0][0].

  • @music-mw3qt
    @music-mw3qt Před 2 lety

    Great exploration

  • @multitech1719
    @multitech1719 Před 6 lety +1

    int *pB=B; for a 2 by 3 array and int (*pB)[3]=B; both compiled perfectly returning same output without any error using Codeblocks.

  • @lekkasdimitrios3628
    @lekkasdimitrios3628 Před 9 lety

    Really well explanation - keep it up mate !

  • @kamayosh1
    @kamayosh1 Před rokem

    thank for your helpful lesson

  • @sayantaniguha8519
    @sayantaniguha8519 Před 3 lety

    3:48
    You meant instead of writing 1st line as **p = A* ,
    We can also write it as *p=A* ?

  • @mahipalsingh-yo4jt
    @mahipalsingh-yo4jt Před 3 lety

    great explanation..........!

  • @srinivasanbaskaran4580

    thank you. the vedio was very helpful

  • @vineethreddymadadi7940

    Awesome stuff!

  • @pveldhose6211
    @pveldhose6211 Před 7 lety +1

    sir write a program to find the sum of both diagonals separately of 2D array

  • @amritmalla
    @amritmalla Před 5 lety

    For n dimensional array by dereferencing it by n asterisk, it will completely dereference the pointer to give the value
    for e.g. b[2][2][2],
    ***b = value in the b[0][0][0],
    so ***b + 1, here 1 is added to the value of array
    **b + 1, means that pointer to int array ( 4 byte is added )
    *b +1, means that pointer to 1d array of size 2( 8 byte is added)
    b + 1, means that pointer to 2d array of size 2X2 ( 16 byte is added)

  • @2311kamal
    @2311kamal Před 2 lety

    the best video ever!!

  • @smerabunuwara296
    @smerabunuwara296 Před 6 lety

    great tutorials thank u

  • @adamouabdramane6624
    @adamouabdramane6624 Před 10 lety

    Thank you U R THE BEST

  • @logio7663
    @logio7663 Před 5 lety

    Helpfull, thank you .

  • @yashpandey9550
    @yashpandey9550 Před 8 lety +6

    At 8:27 , you were trying to explain B+1 and *(B+1)....Its a bit confusing ! How B+1 and *(B+1) giving the same result , i.e. 412 ???? Please explain :D Thanks !

    • @sandrok14
      @sandrok14 Před 8 lety +3

      +Yash Pandey That is an error I suppose. It should give us value 4

  • @jingfanwong4755
    @jingfanwong4755 Před 7 lety +1

    i am not sure if i understood it, assume we have a 2d array and a pointer to it like this:
    int feld[3][5]; int* pointer[5]; pointer = feld; ok, now lets say i would like to enter the value in the array cell feld[2][4].........would i have to write: *(*(pointer+2)+4) ???

  • @katheringomez8512
    @katheringomez8512 Před 3 lety

    The precedence of the signs does not affect the operation that is doing *(b + 1) + 2. According to my concepts, by the way you are locating the data, it goes to the second element of the array, then desreference and adds 2 to the value.
    Therefore I think it would be necessary to use the parentheses *((b + 1) + 2).
    Could you please correct me, thank you very much for taking the time to explain.

  • @music-mw3qt
    @music-mw3qt Před 2 lety

    You have explained well

  • @mirageleung1575
    @mirageleung1575 Před 3 lety +2

    First off, thank you so much for these videos. They are phenomenal.
    I'm at 6:10 and am a bit confused about *B as it's not declared as a pointer. How is *B = B[0] = &B[0][0], I would guess that *B was dereferencing, but then wouldn't get the value instead?

    • @samdavepollard
      @samdavepollard Před 3 lety +8

      B is the name of our 2d array.
      That name acts as a pointer to the first element in the array.
      But the first element in the array is not an int - it's a 1d array of ints, called B[0]
      Hence, B = &B[0]
      Dereferencing gives us *B = B[0]
      Now, B[0] is a 1d array of ints.
      We know that the name of an array can be used as a pointer to the first element in that array.
      So the name B[0] points to the first element in that array of ints
      In other words, B[0] = &B[0][0]
      Hope that helps.
      PS. Also worth noting that since *B = B[0] = &B[0][0]
      if we dereference everything we get
      **BB = * B[0] = B[0][0]
      In other words, dereferencing the name of a 2-d array twice gives us the first element in the first row.

    • @418_akshitasharma3
      @418_akshitasharma3 Před 2 lety +2

      @@samdavepollard thank you!!!!! I was so fucking confused!!!

    • @smrtfasizmu6161
      @smrtfasizmu6161 Před 2 lety

      *B gets you B[0], however B[0] is itself an array and array, so B[0] is a memory address of the array whose elements are B[0][1][2]

  • @limitless1692
    @limitless1692 Před 4 lety

    Very Valuable Video :)

  • @THEtruth8474
    @THEtruth8474 Před 8 lety

    at 5:43 i dont get it i can also define a 1d array of 3 integers like int *p , p = (int *)malloc(sizeof(int)) . declaration of a variable pointer and array pointer are the same . so int *p = b[0] should return a pointer pointing to 1d array of 3 integers which is p which is pointing to b[0][0] . can some one explain me this ??????

  • @MrAltQQer
    @MrAltQQer Před 7 lety +3

    You're a Monster.

  • @AishLovesSpaghetti
    @AishLovesSpaghetti Před 3 lety +1

    But in the previous videos you said that arithmetic operations on array will result in error but such incrementation operations can be performed on pointers. But here B is the name of the array.

  • @pavankumar-hu1sw
    @pavankumar-hu1sw Před 8 lety

    thanks, please upload some more videos