Pointers and 2-D arrays

  Рет қаралды 487,066

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 307
@Phoenix01914
@Phoenix01914 4 жыл бұрын
Indians came from another planet, thank you very much for the awesome explanation. Greetings from Italy!
@anabeatriz8835
@anabeatriz8835 3 жыл бұрын
Indians that are educators yes, Indians that are on tiktok no
@dharaniidharkatikaneni4973
@dharaniidharkatikaneni4973 3 жыл бұрын
@@anabeatriz8835 yeah
@satyamrajput825
@satyamrajput825 3 жыл бұрын
But in everfield indian always beat other
@Phoenix01914
@Phoenix01914 3 жыл бұрын
@@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 3 жыл бұрын
@@Phoenix01914 yeah ! i agree with your thoughts but it is not a good thing to condemn anyone's
@michaelpatterson1096
@michaelpatterson1096 2 жыл бұрын
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.
@sudhadevi6692
@sudhadevi6692 Жыл бұрын
Didn't understand Help me
@sushmitham1722
@sushmitham1722 Жыл бұрын
this helped to clear my doubt thanks:)
@ibbidev
@ibbidev Ай бұрын
this makes so much more sense. wow.
@lautarodelucia6480
@lautarodelucia6480 7 жыл бұрын
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!
@jeffflammer9606
@jeffflammer9606 8 жыл бұрын
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 6 жыл бұрын
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/
@KishanKumar-mz3xr
@KishanKumar-mz3xr 5 жыл бұрын
Thanks for watching. I mean why? . . . THANKS FOR MAKING bruh
@rittenbrake1613
@rittenbrake1613 4 жыл бұрын
yes absolutely
@shubhamshinde5643
@shubhamshinde5643 4 жыл бұрын
That what I thought bro
@shubhamshinde5643
@shubhamshinde5643 4 жыл бұрын
You steal it
@mrBlagstock
@mrBlagstock 4 жыл бұрын
Really enjoy listening to him
@huysaysoui
@huysaysoui Жыл бұрын
I can’t believe you describe such a complex concepts in this way. Good channel, i will see you a lots
@AbhimanyuAryan
@AbhimanyuAryan 10 жыл бұрын
*_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 8 ай бұрын
hey 9 years have passed look at your comment
@Schannel012
@Schannel012 3 жыл бұрын
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.
@shashankkhemka1444
@shashankkhemka1444 8 жыл бұрын
This is the best explanation that I have seen so far for this topic. You are really amazing !!
@bukubukuchakama6005
@bukubukuchakama6005 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
@mycodeschool
@mycodeschool 11 жыл бұрын
Please watch the video "Pointers and arrays" in this series. It will help you understand the concept.
@chennayaianjc3306
@chennayaianjc3306 4 жыл бұрын
Please man come on and do more videos on data structures and interview questions , that make our lives good
@peterpace3379
@peterpace3379 4 жыл бұрын
You should really consider coming back to this channel brother. We need you!
@raunakmaheshwari2034
@raunakmaheshwari2034 7 жыл бұрын
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 7 жыл бұрын
thanks
@Aditya-us5gj
@Aditya-us5gj 5 жыл бұрын
Thanks man ! that was helpful
@Mangosrllysuck
@Mangosrllysuck 4 жыл бұрын
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?
@Schannel012
@Schannel012 3 жыл бұрын
@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.
@Schannel012
@Schannel012 3 жыл бұрын
@@Mangosrllysuck Did I get it right, is *(B + 1) + 1 equal to 416?
@ulysses_grant
@ulysses_grant 7 жыл бұрын
You NAILED it! This is the BEST class of Pointers and 2-D arrasys I've ever seen. FOR GOOD. Thank you so much!!
@jinyunsiwu
@jinyunsiwu 7 жыл бұрын
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
@mycodeschool
@mycodeschool 11 жыл бұрын
&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 5 жыл бұрын
Sir *B means dereferencing then how it could be &B[0][0]
@zezo22abc
@zezo22abc 4 жыл бұрын
how B[0][0] and &B[0][0] the same the 1st give me the value and 2nd give me the address
@tunamusic2314
@tunamusic2314 4 жыл бұрын
@@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
@mycodeschool
@mycodeschool 11 жыл бұрын
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.
@codewho819
@codewho819 3 жыл бұрын
hello :)
@f1ame0n188
@f1ame0n188 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 ❤❤
@SuperTurkce
@SuperTurkce 7 жыл бұрын
Explained really beautifully! Thanks for allocating your time for creating this series of lectures.
@shivagameon
@shivagameon 9 жыл бұрын
superb video series , none I have seen that clears concepts in pointers this deep and lucidly.
@wsmao1154
@wsmao1154 8 жыл бұрын
it's the best tutorial that i've heard thanks for all effort you made !
@munbee_
@munbee_ 7 жыл бұрын
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.
@chennayaianjc3306
@chennayaianjc3306 4 жыл бұрын
A best teacher, explains clearly in one single line,
@ianchandra4107
@ianchandra4107 3 жыл бұрын
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.
@waleedosama1630
@waleedosama1630 7 жыл бұрын
i can not find someone bettr than you in anything you explain ... you are awesome ...keep up the good work ..thanks
@gianniskurgiakis739
@gianniskurgiakis739 4 жыл бұрын
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!
@Schannel012
@Schannel012 3 жыл бұрын
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 2 жыл бұрын
B[0] = &B[0] = &B[0][0] = B = &B = *B all gives same thing i,e same address
@Schannel012
@Schannel012 2 жыл бұрын
​@@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; }
@Schannel012
@Schannel012 2 жыл бұрын
@@happyteen7195 Here is a video which explains this with code kzbin.info/www/bejne/nJLPfHWHi7yGgtk
@Schannel012
@Schannel012 2 жыл бұрын
@@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; }
@ShopperPlug
@ShopperPlug 2 жыл бұрын
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.
@jonvonnoobman2823
@jonvonnoobman2823 2 жыл бұрын
Dude, u rock! U explain stuff much better than IIT profs. And yeah, this is coming from an IIT fresher.
@ryankhullar6289
@ryankhullar6289 Жыл бұрын
kaunsi IIT Hai?
@mirageleung
@mirageleung 4 жыл бұрын
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 4 жыл бұрын
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 3 жыл бұрын
@@samdavepollard thank you!!!!! I was so fucking confused!!!
@smrtfasizmu6161
@smrtfasizmu6161 3 жыл бұрын
*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]
@shadabahmed4547
@shadabahmed4547 4 жыл бұрын
sir really you have very deep knowlege.My concepts are cleared so much ,now i have to just apply it in real code
@jupiterscreams
@jupiterscreams 8 жыл бұрын
Thank you for this tutorial. Very easy to understand!
@225mrraj
@225mrraj 11 жыл бұрын
u r simply the BEST on youtube.!!
@minatorman5047
@minatorman5047 5 жыл бұрын
b+1 gives 412 !! *(b+1) should gives the value stored in that particuler address why it gives an addresss ??
@abdimalikosman559
@abdimalikosman559 4 жыл бұрын
That is what i was thinking too.
@charansashidhar2214
@charansashidhar2214 4 жыл бұрын
@Vaneet Gupta what is *B
@balaganesh3440
@balaganesh3440 4 жыл бұрын
@@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 3 жыл бұрын
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 :)
@sans.creates
@sans.creates 3 жыл бұрын
@@saimanognanelavelli8005 do u wanna say B+1 AND *(B+1) are the same?
@amizan8653
@amizan8653 8 жыл бұрын
This video was infinitely helpful, thanks for posting!
@travellingsLenses
@travellingsLenses 6 жыл бұрын
One of the best stuff available on the internet. :) Keep it up.
@1qaribullah
@1qaribullah 7 жыл бұрын
Great explanation... No need to study books. Thumb up..!!!!!!!!
@mycodeschool
@mycodeschool 11 жыл бұрын
Thanks Adamou :)
@Xardas_
@Xardas_ 2 жыл бұрын
Pointers are no longer over my head. Thanks a lot !
@johnparks6936
@johnparks6936 8 жыл бұрын
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 8 жыл бұрын
Exactly my doubt
@johnparks6936
@johnparks6936 8 жыл бұрын
Abhimanyu Bhardwaj Yea, I still can't understand. Hopefully someone will help us.
@shishupal0iitb87
@shishupal0iitb87 8 жыл бұрын
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 8 жыл бұрын
That makes so much sense - thank you!
@_kahini
@_kahini 7 жыл бұрын
+Shishupal is **(B+1) and *(*B+1) the same or u made a mistake ?
@dzzzzzt
@dzzzzzt 9 жыл бұрын
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 8 жыл бұрын
+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.
@Shaddad_Gomid
@Shaddad_Gomid 5 жыл бұрын
Thanks a lot, the most informative and to-the-point video about this subject
@ahmeddeiaa3943
@ahmeddeiaa3943 7 жыл бұрын
this tutorial is quite amazing. Thank you and please keep it up
@CylinderHead1
@CylinderHead1 9 жыл бұрын
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 !
@multitech1719
@multitech1719 6 жыл бұрын
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.
@shikharchandra3028
@shikharchandra3028 9 жыл бұрын
@mycodeschool shouldn't * print the value instead of address? Please clarify
@_kahini
@_kahini 7 жыл бұрын
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 7 жыл бұрын
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.
@Schannel012
@Schannel012 3 жыл бұрын
But the value of B[0] is an array, and arrays are represented as a memory adress of their first element.
@rishabh6051
@rishabh6051 4 жыл бұрын
thanks for making this video, I was very struggling with pointer to array. You have explained very well
@jeromyclassyca7063
@jeromyclassyca7063 3 жыл бұрын
This is the only lesson I found difficult that this man taught
@siishasha2176
@siishasha2176 5 жыл бұрын
You are an Angel! Thank you so much for all these amazing videos!
@deepeshshrestha1036
@deepeshshrestha1036 3 жыл бұрын
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.❤️
@yashpandey9550
@yashpandey9550 8 жыл бұрын
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 8 жыл бұрын
+Yash Pandey That is an error I suppose. It should give us value 4
@btcblade3334
@btcblade3334 8 жыл бұрын
bro your videos are so good and concise
@MrViney333
@MrViney333 9 жыл бұрын
@mycodeschool Thanks to you pointers is clear to me. Thank you very much
@priyasukumaran
@priyasukumaran 5 жыл бұрын
Sir.. you doing a great job.. thank you so much..!!
@amritmalla
@amritmalla 5 жыл бұрын
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)
@theadel8591
@theadel8591 3 жыл бұрын
excellent explanation, not a strightforward concept (pointers of 2-D arrays) but manageable with some practice !
@14JINU14
@14JINU14 10 жыл бұрын
Excellent walk-through. Well explained with very good examples. Thank you so much.
@user-or7ji5hv8y
@user-or7ji5hv8y 6 жыл бұрын
you are really a great teacher! such lucid explanation.
@greymind0072
@greymind0072 3 жыл бұрын
How come deferencing a pointer still giving as the address and instead of value at that address-> timestamp[ 8:28 ] => here *( B+1) = B[1] how this can equal to &B[1][0] = 412 ?......isn't deferencing of pointer var should give us the value and not the address ???
@roshaniguthe7983
@roshaniguthe7983 7 жыл бұрын
very good lecture....specially memory allocation topic is very nicely explain
@shahirabdullah5438
@shahirabdullah5438 9 жыл бұрын
sorry i wanted to tell about 6:23 not 5:59, there he used asterisk in B to print the adress not value of B ? and he said *B = B[0] = &B[0][0] in 6:16 , i can understand for 1D *B = B[0], but 2d seems totally confusing to me for this *B = B[0] = &B[0][0] :(
@deepakdev8038
@deepakdev8038 9 жыл бұрын
B[0] is the name of the 1st array.So,name of an array would giv u the address of first element of that array so,B[0]==&B[0][0]
@garryharry1024
@garryharry1024 9 жыл бұрын
+Deepak Devarakonda OHH... That makes complete sense! Thanks Deepak for this clarification. I had the same question as Shahir...
@ChekuriKavitha
@ChekuriKavitha 11 ай бұрын
A very good explanation on pointers. Plz give answer for *(B+1)[0]
@cokpot635
@cokpot635 11 жыл бұрын
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 10 жыл бұрын
Hi do knw the ans now ???
@mayukh_
@mayukh_ 10 жыл бұрын
No to get 4, you have to write **(B + 1) or 0[1[B]]
@garryharry1024
@garryharry1024 9 жыл бұрын
+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 7 жыл бұрын
wrong
@probhakarsarkar2430
@probhakarsarkar2430 7 жыл бұрын
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].
@moony1926
@moony1926 4 жыл бұрын
Super super helpful and clear! Thank you so much!
@AishLovesSpaghetti
@AishLovesSpaghetti 3 жыл бұрын
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.
@03Karthikeyan
@03Karthikeyan 9 жыл бұрын
Thanks man! I had to listen to this couple of times, but it made sense.
@SmartProgramming
@SmartProgramming 6 жыл бұрын
very helpful video sir, the way you have explained is really appreciating, thank you 👍👍
@amanpahwa211
@amanpahwa211 3 жыл бұрын
9:22 reference with green colour. NICE
@jamejustice00
@jamejustice00 9 жыл бұрын
does anybody find that what he said in 5:50 is incorrect? I created a 2d array and a pointer and still can assign the array to the pointer as I expected; p = array. As far as I concern, array hold the address of the its first element, which in turn holds its first element. As a result, the outer array actually hold the address of the first element of its first element, saying a character in my example. He said c compiler would cause error because B hold address of a multi array. But again, the address of the array is the address of its first element. So, I don't see the difference between assign an 1d array to a pointer and a multi-d array to a pointer. And this really make the difference between array and pointer more confused to me. Any one can point out the difference?
@TheSeeker14491
@TheSeeker14491 9 жыл бұрын
The GCC v4.8.3 compiler indeed lets me compile, but gives the warning "initialization from incompatible pointer type". You are right in that if 'b' is a 2d array and you use 'int *p = b', 'p' will have the same value as if you did 'int (*p)[3] = b'. The problem comes when you dereference 'p'. You will get an error when you use '**p' or 'p[1][0]' for example. If you use 'int *p = b' you are not telling the C compiler that the ints at address 'b' come in sets of 3, and it needs this information to do the required pointer arithmetic.
@kautukraj
@kautukraj 5 жыл бұрын
Very helpful.
@apoorvsharma3503
@apoorvsharma3503 9 жыл бұрын
hey but i think that * is used to print the value at the addres ....but in video u r print the address while using * .....{asking u toclear my confusion}
@idontevenknow3707
@idontevenknow3707 6 жыл бұрын
this is because its a 2D array, so there is an added layer. One *, will give you one of the two arrays, whereas two * will reach the value at the given address.
@BBaDDaYY
@BBaDDaYY 6 жыл бұрын
I think he sorted it out himself throughout those years :D
@kaizhang6768
@kaizhang6768 6 жыл бұрын
in a harder way XD
@anondoggo
@anondoggo 5 жыл бұрын
@@idontevenknow3707 Thanks for the clarification. This confused me a lot as well.
@AffaAu
@AffaAu 4 жыл бұрын
Great effort, great explanation. Thanks.
@sahilkanojia2531
@sahilkanojia2531 7 жыл бұрын
sir, I will understand good from your excellent explaination thank you so much
@THEtruth8474
@THEtruth8474 8 жыл бұрын
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 ??????
@shiwangiagrawal8549
@shiwangiagrawal8549 6 жыл бұрын
Very good video. Thanku soo much. Helped a lot.😊😊
@Rakeshrajeev94
@Rakeshrajeev94 5 жыл бұрын
Very much helpful. Thanks team 😊
@09charger1
@09charger1 8 жыл бұрын
@8:25, I don't understand how B+1 and *(B+1) give you the same answer???
@kimron92
@kimron92 7 жыл бұрын
B+1 is a pointer to a one dimensional array of length 3 in this case.. If you do (B+1)+1 you will get 424.. *(B+1) is a pointer to first element of an array of length 3. If you do *(B+1)+1 you will get 416.. Here you can see that B+1 and *(B+1), although are different from each other in how they behave, here they are pointing to the same thing i.e the address of the location where 412 is stored.. Since the address is same we get the same value for both of these pointers.
@patrasculucian2403
@patrasculucian2403 6 жыл бұрын
B+1 = address at B[1] *(B+1) = *B[1] = address at B[1][0] address at B[1] = address at B[1][0] But this is not quite the same thing. They got the same adress but there is a difference between them. Let's suppose: B[0] has adress 400 B[0][0] has adress 400 also. The difference comes with math opperations: B[0] + 1 = B[1] (address 412) B[0][0] + 1 = B[0][1] (address 404)
@afeezramoni4781
@afeezramoni4781 6 жыл бұрын
I was in doubt but I trust this guy's stuff. So I ran these few lines to validate....mehn, he was right as usual int main() { int B[2][3]; int* point2D = B; printf("The address of &B[0] is %p ", &B[0] ); printf("The address of *B is %p ", *B); printf("The address of B+1 is %p ", B+1 ); printf("The address of &B[1] is %p ", &B[1] ); printf("The address of *(B+1) is %p ", *(B+1) ); printf("The address of B[1] is %p ", B[1]); printf("The address of &B[1][0] is %p ", &B[1][0] ); } See results: The address of &B[0] is 0x7ffee9c11a60 The address of *B is 0x7ffee9c11a60 The address of B+1 is 0x7ffee9c11a6c The address of &B[1] is 0x7ffee9c11a6c The address of *(B+1) is 0x7ffee9c11a6c The address of B[1] is 0x7ffee9c11a6c The address of &B[1][0] is 0x7ffee9c11a6c
@vasudhadixit538
@vasudhadixit538 6 жыл бұрын
Afeez Ramoni How can be your address value contain characters ?
@zezo22abc
@zezo22abc 4 жыл бұрын
@@vasudhadixit538 because this is a hexadecimal base and a means 10 c means 12 to f means 15 and so on
@krishnamurthynaik5497
@krishnamurthynaik5497 4 жыл бұрын
At 11:23 b is the address of 1st element that is 400 and *b is 2 and *b+1 is 3 and *(*b+1) is the address of 3 that is 404 not 3
@dharmikmistry8781
@dharmikmistry8781 4 жыл бұрын
Thanks for your great efforts 🔥🔥😍🤗
@nuradilzholmukhan8672
@nuradilzholmukhan8672 6 ай бұрын
holy shit what a golden video! THANKS
@katheringomez8512
@katheringomez8512 4 жыл бұрын
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.
@jingfanwong4755
@jingfanwong4755 8 жыл бұрын
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) ???
@sayantaniguha8519
@sayantaniguha8519 4 жыл бұрын
3:48 You meant instead of writing 1st line as **p = A* , We can also write it as *p=A* ?
@adelleshob3660
@adelleshob3660 Жыл бұрын
Thank you so much you solved my problem !!
@farezuanruzlan292
@farezuanruzlan292 9 жыл бұрын
+mycodeschool is it the same case for 2d array of strings?
@TheMateyl
@TheMateyl 6 жыл бұрын
great explanation
@2311kamal
@2311kamal 2 жыл бұрын
the best video ever!!
@MrAltQQer
@MrAltQQer 8 жыл бұрын
You're a Monster.
@thebishalpaul
@thebishalpaul 5 жыл бұрын
how an integer can be of 4 byte as integers at most in of 2 byte?
@zezo22abc
@zezo22abc 4 жыл бұрын
it depends on the compiler if you use a 32-bit system then integer will be 4 bytes >>> 2 bytes means that you use a processor of 16-bit also if the processor is 64-bit then int will reserve 8 bytes neither 2 nor 4 , hit : if you want to check the volume of your int you can use this statment printf("%d",sizeof(int)); also you can replace int with any data type like char, double and so on .
@snv1996
@snv1996 5 жыл бұрын
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)
@mdmurtaza8321
@mdmurtaza8321 2 жыл бұрын
He is software engineer at google
@shahirabdullah5438
@shahirabdullah5438 9 жыл бұрын
can anybody plz help me out? B in 5:59 the or &B[0] is showing 400. why? should'nt it print the value on B?
@shahirabdullah5438
@shahirabdullah5438 9 жыл бұрын
thanks
@notepad800
@notepad800 8 жыл бұрын
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)??
@pveldhose6211
@pveldhose6211 7 жыл бұрын
sir write a program to find the sum of both diagonals separately of 2D array
@gokuafrica
@gokuafrica 9 жыл бұрын
finally got it. Thank you!!!!!!
@karimshaikh3900
@karimshaikh3900 3 жыл бұрын
Very well explained!
@sagarsaha3762
@sagarsaha3762 6 жыл бұрын
Hey, the website at mycodeshool.com doesn't' work at all. It says "502 Bad Gateway". Please fix this immediately.
@PetBuddies
@PetBuddies 3 жыл бұрын
So good explanation __
@pavanbhalkey4309
@pavanbhalkey4309 8 жыл бұрын
can any explain the point at 8:50 plzz how can *(B+1)+2 =420?? im getting 6 since i) B+1 = 412 ii) *(B+1)=4 iii)*(B+1)+2=4+2=6
@SaurabhSingh307
@SaurabhSingh307 8 жыл бұрын
*(B+1) points to the second row i.e. B[1] . So *(B+1) =address of B[1]=412. Now *(B+1)+2 "navigates" to two elements forward the base i.e. points to B[1][2]. So, *(B+1)+2 = address of B[1][2]= 420. Alternatively, it can be seen that since we have to move forward 2 elements in *(B+1) i.e. B[1]. So, *(B+1)+2 will now point to address that is 2 integer element farther to the base address of B[1] => 412 +2*memory taken by 1 integer( since the pointer is of int type) element = 412 + 2*4= 420
@pedroantoniodesouzasilva2068
@pedroantoniodesouzasilva2068 5 жыл бұрын
Thank you very much, my friend!
@vivekd4278
@vivekd4278 5 жыл бұрын
Nice explanation!
@Utshaw
@Utshaw 6 жыл бұрын
5:56 Here, he wrote , int (*p)[3] = B; I couldn't understand the (*p)[3] part. Can anyone explain me ??
@songforged
@songforged 5 жыл бұрын
Brackets generally mean that you have to read/perform what's inside them first. So the fact that *p is in brackets mean that "p is a pointer..." and the [3] outside it then means that "... that points to an array of size 3."
@xMrJanuaryx
@xMrJanuaryx 10 жыл бұрын
The following code prints Robert. Why is that so if c is simply a pointer to the first element in the array? Shouldn't it be printing an address to the first element in the array? int main() { char c[] = "Robert"; printf("%s", c); return 0; }
@talhaanwar2178
@talhaanwar2178 8 жыл бұрын
+Robert Murch int main() { char c[] = "Robert"; printf("%p", c); return 0; } Just replace %s with %p.
@nafisfaiyaz7543
@nafisfaiyaz7543 6 жыл бұрын
when you write %s, the compiler starts looking for null character. so, writing %s will give you the whole array.
Pointers and multidimensional arrays
16:45
mycodeschool
Рет қаралды 246 М.
you will never ask about pointers again after watching this video
8:03
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 21 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 19 МЛН
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
Introduction to Two-Dimensional (2D) Arrays
10:20
Neso Academy
Рет қаралды 721 М.
Pointer types, pointer arithmetic, void pointers
10:57
mycodeschool
Рет қаралды 490 М.
C 2D arrays ⬜
7:33
Bro Code
Рет қаралды 98 М.
Pointers in C / C++ [Full Course]
3:47:23
freeCodeCamp.org
Рет қаралды 4,7 МЛН
Function Pointers in C / C++
11:57
mycodeschool
Рет қаралды 439 М.
C pointers explained👉
8:04
Bro Code
Рет қаралды 207 М.