Working with pointers

Поделиться
HTML-код
  • Опубликовано: 24 окт 2024

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

  • @ChristianAbbott2
    @ChristianAbbott2 10 лет назад +529

    These explanations are excellent, you're putting my professors to shame

    • @mycodeschool
      @mycodeschool  10 лет назад +60

      Christian Abbott Thanks a lot :)

    • @vfThome
      @vfThome 8 лет назад +58

      I learned more from his videos in one day than from 1 semester of college.

    • @psawyer871
      @psawyer871 7 лет назад +2

      Exactly!

    • @minepro1206
      @minepro1206 5 лет назад +1

      Mine too.

    • @ritabratamandal2429
      @ritabratamandal2429 4 года назад +1

      @@mycodeschool which compiler are you using?

  • @otownsend7819
    @otownsend7819 8 лет назад +211

    You taught this concept better than how it was taught in Harvard's introduction to computer science class! thank you :)

    • @prakharmvm
      @prakharmvm 7 лет назад +8

      cs50 girl :)

    • @k.osiyuk
      @k.osiyuk 7 лет назад +1

      Are you Harvard girl? )

    • @pavanshinde8154
      @pavanshinde8154 6 лет назад

      Olivia Townsend , Are you Harvard's student?

    • @zenchiassassin283
      @zenchiassassin283 5 лет назад +2

      @@k.osiyuk lmao

    • @alirezaghodsipoor2239
      @alirezaghodsipoor2239 5 лет назад +4

      Title are just titles. We are men of titles. We shouldn't be.
      I know it sounded so philosophical!

  • @Fadin19
    @Fadin19 10 лет назад +49

    This is not "Playing with Pointers" like you said, this is an excellent in depth explanation on C Pointers.
    Thank you so much!

  • @garryharry1024
    @garryharry1024 9 лет назад +14

    Hey you are seriously gifted man... I honestly wish I was paying you my tuition and not my school. Like the other comment said you are putting my professors to shame. Keep what you are doing man... you are great at it.

  • @grandtheftautosanan1
    @grandtheftautosanan1 8 лет назад +37

    Thank u for your simple english and great explaination!

  • @shivamverma9447
    @shivamverma9447 3 года назад +10

    These lectures are pure GOLD. Best lectures ever uploaded on RUclips. HatsOFF man........ :)

  • @shrey15
    @shrey15 8 лет назад +3

    Man, you're an amazing teacher. I was fed up at college when i wasn't able to understand anything about pointers and your videos helped me immensely to get those stuff. Keep up the good work man. Hats off to you!

  • @geneon7924
    @geneon7924 7 лет назад +13

    Short and concise, you my friend are legendary at teaching C.

  • @RamytRamyt
    @RamytRamyt 5 лет назад +3

    Your videos are SO much clearer than the explanations our professor gives. Thank you so much!

  • @sandagomithilakarathne7222
    @sandagomithilakarathne7222 4 года назад +8

    Small add up to the course:
    if you are trying to compile these codes from a linux terminal, you might get an error saying " expects argument type int ". its because ,when you try to get the memory address by printf, you cannot specify it as %d as its shown in the video.
    instead of that try to put %p.
    example:
    printf("%d
    ", *p); // this might works fine since the out put is an integer as its expected.
    but to get the address.
    printf("%p
    ", p); //this works for the address

  • @sowmiya77
    @sowmiya77 7 лет назад +7

    Oh My God! After watching this video my thought on pointers concept is totally changed as an easy concept. Perfect Explanation which I never heard before !!!!! :-) Thanks a lot

  • @prathampaila
    @prathampaila 7 лет назад +1

    There is no any other better explanations regarding pointers in youtube. Perfectly teaching with clear examples.

  • @yashpandey9550
    @yashpandey9550 8 лет назад +6

    when you were explaining , you used a statement like "ADDRESS OF P".....But when we are using a pointer P, we are actually referring to the address of integer variable A rather than the address of integer to pointer P...To refer to the address of P we must use another pointer to integer (Cuz P is also a pointer of type integer or a pointer to integer) and we will store the address of pointer variable P in this variable..... :D By the way , your videos are really brilliant , the best i have seen so far ! Thanks :)

  • @prajeshrajsingh998
    @prajeshrajsingh998 4 года назад

    The way you spent tym in making these videos as well as those captions(subtitles), is just great. Thank you so much for spending time and making our future bright.

  • @tejaskiranm4021
    @tejaskiranm4021 7 лет назад +3

    beautiful explanation , I was struggling to understand b4 watching Ur videos , u have made illustrated it in a very simple manner, tq .

  • @pappeepow8985
    @pappeepow8985 8 лет назад +2

    This vid saved me from failing C programming, you sir is amazing.
    You explain 100x better than my professor. so thanks a lot!

  • @Kashif_Javaid
    @Kashif_Javaid 11 лет назад +2

    Best pointer tutorials in RUclips, keep up the good work

  • @zachsmith1423
    @zachsmith1423 7 лет назад +11

    you sir deserve an award....thank you very much!

  • @DGuttyC
    @DGuttyC 8 лет назад +1

    Thank you so much! Being a non-computer science major, I've been studying programming myself and the concept of pointer has been one of the toughest to grasp. Now it makes more sense :)

  • @pawzillasmash
    @pawzillasmash 6 лет назад

    man you're very clear about the explanation which my prof couldn't do over the course of 2 classes. Thanks a bunch! Saved me from understanding the material.

  • @devanshrajoria5418
    @devanshrajoria5418 7 лет назад

    You rocks mycodeschool. Its so fun and easy to do programming with your tutorials.

  • @mboerrigter1
    @mboerrigter1 10 лет назад +2

    Explained clearly and concisely. Brilliant work on the whole series.

  • @mattshu
    @mattshu 6 лет назад +1

    I can't believe I can spend so long confused by pointers and I come across these videos and it all clicks together. Thank you! (Also wonderful accent, it's like the diet version :))

  • @ozzyfromspace
    @ozzyfromspace 5 лет назад +1

    You're a legend bro! I hated dealing with pointers before coming across your playlist, now they seem sensible. Thank you so much! You have brought me joy, and I look forward to making it to your data structures playlist. Best wishes, and I'm excited to see what comes next with this series on pointers.

    • @adzpoweradel3228
      @adzpoweradel3228 9 месяцев назад

      some people said is dead, pray for him.

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

    Yaar this is THE SIMPLEST EXPLAINATION I have seen.Thank you sooo much dude!!

  • @Shadow-lx9rh
    @Shadow-lx9rh 3 года назад +1

    Sir really i thank you very much from the core of my heart. Please make more videos on other topics of programming .

  • @surajsharma939
    @surajsharma939 3 года назад +3

    your legacy will always there ,miss u harsha sir

  • @andrewcarrillo4814
    @andrewcarrillo4814 4 года назад

    Im in my first semester of grad school and taking an intro to C programming class. The professor ruined this concept by not explaining it well and glossing over it. I’ve been struggling with these for 4 weeks and I’m so glad I found these explanations. Everything is coming together in my brain

  • @NeerajSharma-oz1mm
    @NeerajSharma-oz1mm 4 года назад +2

    Sir, first of all - hats off
    You’re doing an amazing job. There is one correction however, sizeof is not a function, it’s an operator which is executed at compile time.

  • @gulnarismaylzad4429
    @gulnarismaylzad4429 4 года назад

    thanks to your contribution to understanding basic logic in C programming. it is really easy to understand clearly.

  • @TheKaveshan
    @TheKaveshan 8 лет назад

    THNAK YOU SO MUCH FOR THESE VIDEOS...FAR BETTER THAN UTILISING MY PRESCRIBED TEXTBOOK. YOU REALLY DONT KNOW HOW MUCH IT IS APPRECIATED. THANK YOU

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

    I totally love the videos and teaching here :) thanks for making more people educated

  • @mycodeschool
    @mycodeschool  11 лет назад

    I do not get your question. Garbage collection is freeing dynamically allocated memory (allocated using malloc or new operator) that is not being used at any point. Whats the relation here?

  • @arjitjain9406
    @arjitjain9406 5 лет назад

    Excellent Explaination , You cleared almost every doubt anyone can have with such ease , just Mind Blowing

  • @cindycruz2010
    @cindycruz2010 10 лет назад +1

    Thank you for the videos. Your explanations make pointers much easier to understand. I have a question, though. Why use pointers to manipulate the int value. Wouldn't it be easier to just change the value directly. I guess I thought pointers were used to copy the integer value so it could be manipulated without changing the original variable value.

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

    Your videos are cool bro. Although from ten years ago but they can help me get more knowledge for programing

  • @mingx009
    @mingx009 10 лет назад +1

    Thanks a lot. The lesson is so much detail and step-by-step. Great.

  • @keremoflu
    @keremoflu 10 лет назад +1

    It was very helpful and professionally ! Thanks for your efforts.

  • @abhishekvarma9235
    @abhishekvarma9235 9 лет назад +1

    Thank u sir u have made my concepts so clear may God bless ur soul...

  • @linxrayan6309
    @linxrayan6309 7 лет назад +3

    Salam alykom
    I find your lessons simple and clear
    thank you

  • @wenjiecheng1391
    @wenjiecheng1391 7 лет назад +4

    Damn this is the greatest tutorial I have ever seen!!! Thank you.

  • @showwavemaharjan3517
    @showwavemaharjan3517 6 лет назад +1

    You sir just made my day.
    Thank you for your contribution. I hope I could repay you some day.

  • @jyoti.m7
    @jyoti.m7 9 лет назад +3

    Thank you for all your hard work professor ,i think you are the next steve jobs....

  • @kavan1773
    @kavan1773 9 лет назад

    Your explanations are very easy to understand. Thanks a bunch! I just subscribed!

  • @bryanp.6255
    @bryanp.6255 9 лет назад +2

    Perfect examples! I learned a lot. Thank you.

  • @willmorgan8830
    @willmorgan8830 5 лет назад

    Excellent teacher. Your videos are pure gold. Thank you ...!

  • @rshparmar4962
    @rshparmar4962 4 года назад +3

    May God Bless your Soul RIP brother. You are missed a lot!!!

  • @jasmine9538
    @jasmine9538 7 лет назад +5

    Can't believe I actually understand this! Thanks

  • @evergreendon6469
    @evergreendon6469 4 года назад

    The best explanation I have ever ever seen all my life, thumbs up ~!

  • @Sarahhh123
    @Sarahhh123 3 года назад

    you´re honestly the best account, thank you so much!!!

  • @Smartboynikso
    @Smartboynikso 11 лет назад

    I have joined NIIT for c language but i couldn't get this level of explanation.
    very gud explanation
    Awesome work thanq :)

  • @WilsenLie
    @WilsenLie 11 лет назад

    Fixed it.. Dude, u are awesome. Your videos help me to understand about pointers.

  • @manilmasd6902
    @manilmasd6902 9 лет назад +5

    Thank you for all your hard work professor :)

  • @rishirajrao5337
    @rishirajrao5337 9 лет назад

    these are really incridble videos.these videos are what i m seeking for..thanks for your work..these are helpful .

  • @GeorgeRodes1968
    @GeorgeRodes1968 8 лет назад +4

    Excellent work! Much appreciated.

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

    mano, ninguém supera a didática desse cara!!

  • @josejimenez850
    @josejimenez850 7 лет назад

    Wow. I did not know you can initialize the "*p" to the address. My book always did the long way. Now I understand how you can pass addresses through the parameter of other functions. Wow thank you for clearing that up. I was getting confused because I thought "*p" only contained a number at which "p" had the address of. But now I see that *p is to tell the c system the the variable p is a pointer!! And omg it makes so much sense

    • @josejimenez850
      @josejimenez850 7 лет назад

      Correct me if I'm wrong!! Please I love to learn my own misconceptions

  • @amitanshupattanayak9065
    @amitanshupattanayak9065 8 лет назад +13

    dude can you do a data file handling tutorial cuz your tutorials are epic

    • @BhargabKakati
      @BhargabKakati 7 лет назад

      same request here

    • @cheems08213
      @cheems08213 5 лет назад

      He is not there anymore, word is that he passed away in an accident.

    • @blackphillip63
      @blackphillip63 5 лет назад

      @@cheems08213 For real?

    • @cheems08213
      @cheems08213 5 лет назад +1

      I did a research on this topic. What I found is that the narrator of the video Animesh is alive and well but the co-founder of mycodeschool who went by the nickname HumbleFool passed away somewhere in 2014-2015 in a car accident. Harsha (HumbleFool) was India's one of the best competitive programmer. Animesh (an alumni of the Indian Institute of Technology) co founded the mycodeschool with Harsha somewhere in 2009. I also read in an article that Animesh is currently working in Google. However I cannot understand why Animesh has stopped uploading videos, maybe it is because of the sudden demise of his founding partner.
      (I googled all this so nothing is official and I could be wrong)

  • @swapnilpawar2044
    @swapnilpawar2044 4 года назад

    sir as u said in last *(p + 1) are not printing garbage. it's printing 2750832 that is increase address of a by 4 byte. its working fine.

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

    Hi, thanks for the great video. In the example at 6:09, I think the printf statement should read ("Address of a is %d
    ", p) instead of ("Address of p is %d
    ", p). p is pointing to a, and by printing p we're showing the address of a, not the address of p.

  • @ranjanaashish
    @ranjanaashish 8 лет назад +34

    At the 6:24 point of this video, the 1st printf statement("address of p is %d",p) which turned out to be 3144576 there should probably be ("address of a is %d,p) ,shouldn't it be?
    Similarly,the 2nd printf("Value at p is %d,*p) printing 10 should (as far i could understand) ("Value at the address stored in p is %d",*p).
    Kindly,clarify.
    Thanks.

    • @Torcika
      @Torcika 8 лет назад

      that also had me confused

    • @abinash138
      @abinash138 7 лет назад

      correct

    • @kovectra
      @kovectra 7 лет назад +1

      Actually he meant the address that pointer p points to not the actual address of pointer p

    • @patrasculucian2403
      @patrasculucian2403 6 лет назад +2

      You are correct!
      At 6:24 could also be: printf("value of p is %d" ,p)
      I think our teacher got a little confused himself.
      Anyway I think he has the best pointer lessons on RUclips

    • @ayazaslam6167
      @ayazaslam6167 6 лет назад +1

      dont be confuse. see p=&a learn to read it like this. left to right. address of a is assign in pointer variable p.
      *p will print value of a and p will print address. remember "HOW TO READ". address of a is assign in p. hope u understand.
      lol i saw now u posted 2 years back
      lol
      any how

  • @fandiks
    @fandiks 6 лет назад +1

    Thanks a lot for making all of these videos! You"re great explaner :)

  • @ayazaslam6167
    @ayazaslam6167 6 лет назад

    u r great.born to teach and learn new things. at 7:45 u cleared my confusion.
    thanks a lot.

  • @monicatentu6802
    @monicatentu6802 10 лет назад +1

    great.....!! thank you so much for all the videos....can u plz upload the videos of java nd c++ too...

  • @mudzi9433
    @mudzi9433 8 лет назад +3

    Thank you so much for these videos! They are really great :)

  • @anondoggo
    @anondoggo 5 лет назад

    Omg. That is so fascinating. I am enthralled by pointers now.

  • @MohitK96
    @MohitK96 8 лет назад

    your teachings are directly attacking my mind;)Gr8 Work

  • @harshithag1035
    @harshithag1035 4 года назад +1

    Hey I have a doubt what happens if I print a pointer with a prefix operator I mean like printf(“%d”,++(p)); when I actually run this code I am getting output with actual address minus 4

  • @tenshiskies
    @tenshiskies 4 года назад

    You are an excellent teacher!

  • @alexsece
    @alexsece 7 лет назад +4

    Thank you very much for the explanation!
    Tip: sound level is very low.

  • @rshparmar4962
    @rshparmar4962 4 года назад

    If he would have been alive the whole programming would have been a lot easy with these awesome explanations.

  • @andrewgreen1970
    @andrewgreen1970 4 года назад +5

    I think that instead of "Address p is" you could have gone with "Address stored in pointer variable p" or "Address pointed to by p" so that beginners could avoid confusion with "Address of p". (Take it from me as someone who for a long time could not understand pointers because of how people and books taught the topic.) Otherwise, great video.

  • @alexbravo7467
    @alexbravo7467 3 года назад

    Excellent Explanation , dear friend , Thank you very much for sharing ...

  • @RahulSingh-xm9js
    @RahulSingh-xm9js 5 лет назад

    I am using GCC compiler by GNU and here's the output I get after executing the code:
    The address of a is 0x7ffee3ebfa0c
    The value at address p is 10
    The size of the integer is 4
    The address of value next to a is 0x7ffee3ebfa10
    The value at address p+1 is -471074272
    Also, to find the value at address p+1, you have to enclose the variable within brackets as (p+1) before the pointer operator, else the compiler increments the value by one unit, i.e., it returns 11.

  • @PRAD61
    @PRAD61 10 лет назад

    Very very good teaching skills.great way of teaching.. why havent you covered other topics like arrays, storage classes etc..

  • @nisargparab8074
    @nisargparab8074 5 лет назад

    Next level explanation....Thanks very much...

  • @mohanaddarwish2307
    @mohanaddarwish2307 9 лет назад

    Dude, i love your videos and i want to tell u i hope u get the same help u r proving us in ur advanced career topics by other cool guys like yourself:))

  • @mohitbv2331
    @mohitbv2331 7 лет назад

    hello, Admin. Thank you very much. *(p+1) will give us some garbage value. but *p +1 will increment the value that p points to 1. However, my question is will the contents that p is pointing to shall change?

  • @TinCarpter
    @TinCarpter 10 лет назад +1

    In 6:21
    Did you mean to write in the printf statements that the address of a is the value of p? because If I understand it correctly, what you showed was the stored value in p, which is the address of a, when you wrote that the address of p is the value in the pointer p.

  • @leixun
    @leixun 4 года назад +5

    *My takeaways:*
    *& vs *:*
    int a=10; \\ declare a variable
    int *p; \\ create a pointer, and we have to initialise it otherwise we will have an error
    p = &a; \\ initialise the pointer 'p' with the memory address of 'a' (i.e. &a)
    int *p = &a; \\ we can also create a pointer and initialise it in one line of code
    int* p = &a; \\ this does the same as the above code
    *Be aware when we are not creating a pointer, 'p' is the pointer (i.e. the memory address) and '*p' is the value at the memory address pointed by 'p'.*
    For example:
    '*p' is the value at the memory address of 'a' (i.e. '&a')
    =the value of 'a'
    =10
    *p = 12; \\ this is called dereferencing, we can change the value of 'a' to 12 using the pointer
    *Index memory*
    p is the memory address of 'a'
    p+1 is the memory address of 'a' + the size of 'int' (i.e. 4 bytes), and if 'a' is in other data types, the size is different

    • @RM-lb7xw
      @RM-lb7xw 4 года назад +1

      Isn't *p = 12 called dereferencing? That is, changing the value at a position using pointers?

    • @leixun
      @leixun 4 года назад +1

      @@RM-lb7xw You are right, fixed.

  • @poojapawar8162
    @poojapawar8162 3 года назад

    Thank you so much, I was so confused you have solved my all doubts

  • @5857612
    @5857612 11 лет назад

    You explain and teach well. Lucky I found this vid.

  • @symbols1984
    @symbols1984 10 лет назад +1

    Thanks for your very helpful videos

  • @JohananJoysingh
    @JohananJoysingh 9 лет назад +4

    You sound like Dhoni... :D .. Good Explanations :)

  • @rztutul8824
    @rztutul8824 7 лет назад +2

    Thanks a lot ...
    i learn so much from this video

  • @mycodeschool
    @mycodeschool  11 лет назад

    This is one dangerous thing about C, using pointers you can access a memory location that you are not supposed to access. As long as you are reading whats written there, its fine, but if you trying to write something... you may be over-writing something critical. So program will either crash or give some unexpected behavior. Write to a memory location which is assigned for some variable, not anywhere.

  • @mycodeschool
    @mycodeschool  11 лет назад +1

    Thanks aarb17!

  • @privateprivate6459
    @privateprivate6459 4 года назад +3

    10:54 he sounds so passionate I love it

  • @abanerjee3704
    @abanerjee3704 3 года назад

    That's hell lot of a job brother, well done.

  • @aashiqahmed5273
    @aashiqahmed5273 3 года назад

    Nice to revisit these old videos

  • @kaursavvy5868
    @kaursavvy5868 9 лет назад

    Hlo Sir...
    Like ur way of teaching very much...Superb job...u r doing over here...
    After listening ur 1 or 2 lectures i m nw bit comfortable with pointers. :)
    I hve a small query
    " U r repeatedly using %d to print the address. But when i use it in my C program it is giving me a -ve number. But if i use %u then it gives me the right address that the pointer points to" Why the two values are different.?

    • @onceajordan
      @onceajordan 9 лет назад

      Kaur Savvy try declaration as "unsigned int a=10".it wont give -ve sign with %d. %u means unsigned that's why it drops the minus sign.

  • @mycodeschool
    @mycodeschool  11 лет назад

    *p should print the value and not the address .. When we are printing p, we are trying to print the address... Your compiler is not allowing that because its expecting an int for "%d" ,,, try printf("%p
    ", p).. "%p" means you are trying to print an address.

  • @djravish4920
    @djravish4920 7 лет назад +1

    i really appreciate you man ! excellent explanation !

  • @aayushigawde5829
    @aayushigawde5829 6 лет назад

    You explain in a lucid manner.

  • @naminhvan8632
    @naminhvan8632 8 лет назад

    Dear mycodeschool and listeners! could you explain me more about your code
    "printf("Address of P is %d
    ", p);" (at 6:22) in time.
    as my understanding, this command will display the address of available (a) that is pointed by pointer P;
    I think if we want to display the address of P we should use
    printf("Address of P is %d
    , &p");
    very happy and thank so much for your lectures!

  • @tepy3506
    @tepy3506 4 года назад

    Thank you for your clear explanation.

  • @ozbjd
    @ozbjd 8 лет назад +8

    Nice video but there is a serious error at 8:28 where you say that because the size of an integer is 4, then p+1 is 4 bytes further on from p. It's correct that it's 4 bytes further on in this case, but not because it's the size of an integer (which for the compiler you are using just happens to be 4). It's the number of bytes needed to store a memory address, which in this case also happens to be 4. If you change the data type to char, which has a size of 1 byte and the pointer + 1 would still be 4 bytes on. Also at 6:21 where you have "printf(address of P")". It's not actually the address of p that you are printing but the address stored at p, which is the address of a. Also, if you want to print memory addresses the proper way to do it is to use %p as the format string and (void*) &p as the argument. This last point is probably beyond the scope of the video but you run the risk of getting errors if you treat a memory address as an integer. .

    • @GurpreetKakar4873
      @GurpreetKakar4873 7 лет назад

      Every byte in memory has an address. So, if you have an int that's 4 bytes and its address is 1000, 1001 is actually the 2nd byte of that int and 1002 is the third byte and 1003 is the fourth. Since the size of an int might vary from compiler to compiler, it is imperative that when you increment your pointer you don't get the address of some middle point in the int. So, the job of figuring out how many bytes to skip, based on your data type, is handled for you and you can just use whatever value you get and not worry about it.So as you were saying for a character the (p+1) will refer to next byte as char type only takes on byte.So in a nutshell pointer arithmetic doesn't work in bytes but in terms of sizeof(pointer base type)-bytes sized blocks.

    • @ozbjd
      @ozbjd 7 лет назад

      I agree with what you are saying in the statement above.
      What I am saying is that it is ambiguous in the video when you use 4 byte addresses and a datatype that uses 4 bytes in the same example. It becomes unclear whether the the fact that the pointer plus 1 is 4 bytes on is because of the size of the 4 byte integer datatype or because you have a machine that uses 4 bytes for addresses.
      The reason why p+1 is 4 bytes further on is because in the video you are using 4 byte addresses. For example if you had a 64 bit machine and a 4 byte integer datatype then addresses i.e. pointers would occupy 8 bytes and each item of data would occupy 4 bytes. So the address at 1000 to 1007 would point to the 4 byte integer a. Incrementing the pointer to p + 1 would be to use the 8 byte address stored in the memory addresses from 1008 to 1015 (i.e. 8 bytes on from 1000).
      Incrementing pointers is dependent on the size of addresses, not on the size of the datatype being pointed at.

    • @GurpreetKakar4873
      @GurpreetKakar4873 7 лет назад +3

      On a 64 bit machine
      int main()
      {
      int *p;
      int a=10;
      p=&a;
      printf("%d
      ",a);
      printf("%p
      ",p);
      printf("%p
      ",p+1);
      printf("%d
      ",sizeof(int));
      return 0;
      }
      Output is
      10
      0061FF28
      0061FF2C
      4
      Why incrementing the pointer shift the address to only 4 bytes and not 8 bytes as you suggested?

    • @GurpreetKakar4873
      @GurpreetKakar4873 7 лет назад +1

      No problem Bernard. These types of discussions should help the viewers.Peace.

    • @ozbjd
      @ozbjd 7 лет назад +9

      Hi Gurpreet. I have to eat a bit of humble pie here. I was wrong. You are right. Adding 1 to a pointer like you have done in the program above gives a memory address which is the memory address stored in the pointer + sizeof(whatever datatype the pointer points to). In this case since p is pointing to an integer of 4 bytes in size the address pointed to is 4 bytes past the address of variable a. If p was pointing to a char of 1 byte in length then adding 1 would point to an address one byte along from whatever address it was pointing to.
      #include
      int main()
      {
      int *p;
      int a=10;
      p=&a;
      printf("%d
      ",a);
      printf("%p
      ",&a);
      printf("%p
      ",p);
      printf("%p
      ",p+1); // calculates 1*4 and adds it to p
      printf("%p
      ",p+10); // calculates 10*4 and adds it to p
      printf("%d
      ",sizeof(int)); // integer is 4 bytes in size
      printf("%d
      ",sizeof(p)); // pointer is 8 bytes in size but irrelevant
      return 0;
      }
      10
      0x7ffe14f30434
      0x7ffe14f30434
      0x7ffe14f30438
      0x7ffe14f3045c
      4
      8

  • @SuhailAmeen46
    @SuhailAmeen46 10 лет назад

    love this guys explanation

  • @mohitbv2331
    @mohitbv2331 8 лет назад

    Wow, I understood about pointer's very well. Thanks. But I really did not understand why *(p+1) did not print 11 but prints some garbage value. Could you please answer my question?
    .

  • @kiku_to_herself
    @kiku_to_herself 4 года назад +1

    Summary -
    int a=10;
    int *p=&a;
    p is pointer to integer
    &a and p will give the address of a variable (suppose its 2000)
    *p(value at p) and a will give the value of a that is 10.
    (p+1) will give 2004 as output coz will give the next address which will be after 4 bytes or 2 bytes , depending how much memory integer is taking , you can find it by using - sizeof(int)
    *(p+1) will give the value stored at next 4 bytes which is mostly garbage value