Pointer Arithmetic (Addition)

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

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

  • @iamaprogrammer1022
    @iamaprogrammer1022 5 лет назад +538

    Initially p has address of a[2]... And p=p+2 means two shift towards right from initial address.. So now.. P will have a[4].

  • @tlarson91119
    @tlarson91119 4 года назад +51

    0:50 A shorter way would be to just get rid of the ampersand and [0]. When an array name is used in an expression, the array is automatically cast to a pointer to the first element of the array.
    So one could also write:
    int *p = a;

    • @simonmarabi2661
      @simonmarabi2661 3 года назад +1

      exactly

    • @hetaeramancer
      @hetaeramancer 3 года назад +26

      he's teaching it systematically. mentioning that shortcut will cause confusion to beginners

    • @techmad8204
      @techmad8204 3 года назад +6

      Yes, isn't this the reason why we don't use & in scanf for strings?

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

      @@techmad8204 yeah man

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

      @@techmad8204can you tell me which resources are you using to learn c

  • @abdelrahmanm.6215
    @abdelrahmanm.6215 4 года назад +34

    Your videos have honestly made a HUGE difference in my academic career.
    i thank you from the bottom of my heart for putting in the effort and time.

  • @MrAjaypatole
    @MrAjaypatole 3 года назад +27

    Base Address= 1000 ,
    p= &a[2] = 1008 ,
    p= p+2 = 1008+2*4 = 1016 ,
    p= a[4]

  • @TantawyAhmad
    @TantawyAhmad 5 лет назад +141

    WOW!! Literally, best programming intro and C explanation I've seen so far the series is Amazing!! ❤ and the explanation is very simple😊 Please post daily content👌
    I came here for the "Data Structure intro" but found the explanation worth to review the basics of programming all over again. I'm sure the other playlists are as good as this one.
    Thank you so much!!😊 Please post from the Data Structure part on your road map 🙏
    >>Data Structures:
    1) Stacks
    2) Queues
    3) Linked list
    4) Trees
    5) Binary search trees
    6) Binary heaps
    7) Graphs
    8) Tree traversals

  • @labandaetoilista4873
    @labandaetoilista4873 4 года назад +98

    The answer is : the pointer will point to : a[4]

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

      How

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

      ​@@bhargavskulkarni2855it moves the pointer 2 index forward.
      Thats the fifth index
      Which we write a[4] Because counting begins from 0

  • @nisha..sharma..8554
    @nisha..sharma..8554 3 года назад +5

    I have taken course on udemy in c programming.. but after some days I have seen this channel on RUclips .. and I have a thought about wasting my money on udemy... ❤️❤️❤️... Thank u so much sir..

  • @080_cse_sanjaykarthicks4
    @080_cse_sanjaykarthicks4 3 года назад +3

    Initially I thought that the pointer concept is very complex. But after watching videos of NESO academy about the pointers,I have started to understand the concept. Thanks for the instructor for making me understand the complex concept in an efficient way.

  • @andreeastanciu328
    @andreeastanciu328 5 лет назад +54

    This is the most amazing C tutorial. ❤️ Very good job, I can't wait for the playlist to be finished.

  • @pascalchinedu6705
    @pascalchinedu6705 2 года назад +6

    This series has made me attempt C programs I found difficult.
    I can't thank you enough sir. Better late than never. I'm glad I saw this academy

  • @seunlivefootball
    @seunlivefootball 4 года назад +15

    Wish i could see you and give you a hug, like right now!
    I have been trying to understand this pointer of a thing for more that three days, but here comes NESO ACADEMY which such a lucid explanation. Thank you very much! You've made my day.

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

    No need to multiply by 4 in case of int array. See this example
    int size = 4;
    int arr[] = {1, 2, 3, 4};
    int* p = &arr;
    *(p + 1) = 9;
    for (int i = 0; i < size; i++) {
    printf("%d
    ", arr[i]);
    }
    It should print:
    1
    9
    3
    4

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

    I tried various platforms to learn c but the quality of explanation that u give is next level

  • @Neha-zm7by
    @Neha-zm7by 2 года назад +1

    I never commented on anyone youtube channel but neso how can i thank you i am understanding everything(apart from recursion) and now i think i can pass my exam

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

    Taking care of me in signals, controls, and now during an internship. Great work!

  • @nirbhayparmar
    @nirbhayparmar 4 года назад +15

    a[4], 5th element of the array

  • @mohamedmezid4821
    @mohamedmezid4821 Год назад +3

    Answer of the question:
    After the operation "p = p + 2", the pointer p will now point to the memory address that is 2 elements ahead of its current location.
    Since the initial value of p is the address of the 3rd element of the array i.e &a[2], after the operation p = p + 2, the pointer p will point to the 5th element of the array i.e p = &a[4].
    Therefore, the index of the array after this operation is 4.

  • @sunilkumarreddy6537
    @sunilkumarreddy6537 5 лет назад +16

    It is realy a good explination for me
    apart from the class and coaching section. Thank you sir

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

    i can't express my happiness to find a great lecturer like u
    i am veryveryvery very happpy

  • @ashwanikumarsrivastava1187
    @ashwanikumarsrivastava1187 4 года назад +2

    You are the best teacher for C programming

  • @Tanzimhossain2
    @Tanzimhossain2 Год назад +3

    6:38 a[2+2]= a[4]

  • @niteshsoni8956
    @niteshsoni8956 3 года назад +7

    ANS- index will be 4....Sir thank you so much for teaching and sharing such amazing knowledge of C with us!!

  • @yasharora4300
    @yasharora4300 4 года назад +6

    Thank you so much sir.
    Best explanation on complete RUclips.

  • @tinkukumarsiddharth2281
    @tinkukumarsiddharth2281 4 года назад +2

    I didn't understand the any programming language in the,but here I am learning it with the interest.

  • @studyspectra_1980
    @studyspectra_1980 3 года назад +1

    And is a[4]..as p=p+2 simply means shifting the pointer by 2 units from the initial position in forward direction..ie.from a[2] to a[4]..

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

    If only if this video exists back in 2017, I would have excelled my programming paper. Thanks for the great content.

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

      @jw72jswu728uwj You don't know his circumstances. Maybe he dropped and coming back at it again. Mind your own business.

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

    Thank you so much for these amazing videos. I understood really well what are pointers and literally I understand each point you explain. The best teacher ever for programming. Whoever I meet with doubts in C I will recommend Neso academy for sure

  • @ajmalkhaniit
    @ajmalkhaniit 4 года назад +2

    Index will be 5 bz pointer contains third address of array and we 2 in this so pointer will move 2 position in forward direction

  • @rajivkumawat7940
    @rajivkumawat7940 2 года назад +4

    ans is 4. sir i am 1st year student in iiit gwalior in IT stream. my programming language was going extremly wrost but neso academy saved my engineering life .i saw many youtube channel related to programming language but this one is extremly good. i gain more dept interest in programming because of you. so thank you very much sir for creating such kind of channel which helps all students . 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏thank you very much sir 🙏🙏🙏🙏🙏🙏

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

    primary address is p is array of 3rd element i.e p=&a[2],when we add p=p+2 then new address i.e p=&a[2+2]=&a[4].which refer 5th element.

  • @TEeducation
    @TEeducation 4 года назад +2

    'P' will point the &a[4] of the array, that means i will point he 5th element of thee array.

  • @emperorisalive
    @emperorisalive 7 месяцев назад

    The video explains pointer arithmetic, specifically how adding an integer to a pointer moves the pointer forward by that many positions in the array. It provides examples and explains the underlying memory layout.
    Key moments:
    00:00 Understanding pointer arithmetic is crucial in programming. Adding an integer to a pointer moves it to the next memory location, not just by the integer value, due to memory allocation.
    -Pointer arithmetic involves moving pointers to different memory locations based on integer additions.
    -Explaining the concept of adding an integer to a pointer using a practical example with array indexing.
    -Detailing the memory allocation and the impact of adding an integer to a pointer on memory addresses.

  • @preetimadas3517
    @preetimadas3517 3 года назад +1

    It will be a[4].... And sir you are amazing..... I m literally getting to understand C learning from u....

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

    If we want a[2+2] a[4] we have to multiply p=p+2*4 if we assume that the data stored is an integer.... and if we assume that the value of the integer a[2] is in 1002 to go to a[4] we have to add 4 and add 4 again 2*4

  • @080_cse_sanjaykarthicks4
    @080_cse_sanjaykarthicks4 3 года назад

    The answer to the h.w qn is 4 as first the pointer pointed to the index 2 and p=p+2 moves 2 positions to the right, and so now the pointer will point to index 4,i.e,p=&a[4]

  • @EyeNeo
    @EyeNeo 3 года назад +1

    Index will be the p[4] which is actually the fifth element of the array.

  • @tayyab.sheikh
    @tayyab.sheikh 11 месяцев назад +3

    H.W problem :
    p = &a[2] ;
    p = &a[2] + 2 ; ❌
    p = &a[2 + 2] = &a[4] ; ✔️

  • @pranavhendre6209
    @pranavhendre6209 Год назад +3

    the answer :-a[4];

  • @priyankarodda1943
    @priyankarodda1943 4 года назад +2

    Excellent Teaching
    I get clear about pointers
    👏👏👏👏👏👏👏

  • @shivamrawat4289
    @shivamrawat4289 4 года назад +2

    HOMEWORK QUESTION
    we will get index 4 i.e.a[4] --(EXPLANATION)------->>>>>suppose we take &a[2]=1000, so according to question (p) is equal to 1000 and if we perform p=p+2*4 as earlier explained in the current video , we will get p=1008 and each element of array ocupy 4 bytes of memory , so definetly after reaching from address 1000 to 1008 we have moved two index value forward means from a[2] to a[4], means from index 2 to index 4. So final ans is we have reached a[4]. hope you all understand :) .

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

      why did the instructor says that we should multiply by 2 by 4 in 5:40

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

      @@devsutong bro simply we can say it is the formula to perform such things and practically if we do this question on compiler same output we get so we can say that we have understood which formula compiler use to perform such functions .

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

      @@shivamrawat4289 ok now i understand, good explanation by the instructor but his English is very misleading

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

    The explanation is like butter

  • @sudipsen3677
    @sudipsen3677 4 года назад +4

    Nice explanation sir ❤️ really amazing .Thank You

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

    Initially p has address of a[2].
    And "p=p+2" means two shift forward from initial address.
    So now - P will have a[4].
    because 2+2=4.

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

    As p contains the address location of a[2]
    p + 2 will be a[4] ie the fourth index of a

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

    p=&a[2]------->address of array 1008--------->elements position is 3rd in array;
    =>p=p+2=p+2*4=1008+8=1016;
    -------->which location is address of array a[4](1016)---->elements position is 5th in array.....

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

    Index of array will be 5
    Pointer will point to a[4]

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

    Initial index value of p=2 and after adding 2 it will become p=4

  • @RAVIVERMA-zy3vs
    @RAVIVERMA-zy3vs 4 года назад

    Lets consider the base address is 1000 and currently the pointer is at 3rd element which means 1000+4+4=1008 is equal to & a[2] and we have to add 2 to it p=p+2 means 1008+2*4=1016 Which is nothing but & a[4] so this is the Answer...

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

    please add more topics! i love your explanation style!!

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

    The answer is a[4] that is the fifth element of the array;//

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

    I'm looking that so many comments are a[4]. But p=&a[2] which means the base value of a[2]. When we write p=p+2, then base value will added with 2. and the output of p will be a base value only. Not a value like a[3],a[4] etc.

    • @samrudhshetty9334
      @samrudhshetty9334 7 месяцев назад

      your totally correct bro.
      my brain was rotting reading the comment sectiom

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

    So the index of the array after this operation is p=a[4]. Sir please let us know whether it js the right answer or not?

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

    this was so clear! thank you for this

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

    pointer p will have address of p[4] hence point to p[4].

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

    Best explanation ever

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

    P points to the array a[4]
    And index will be 5

  • @48_subhambanerjee22
    @48_subhambanerjee22 2 года назад +1

    answer to homework question: it will point to a[4].. that means, 5th element in the array

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

    The index of the array pointed by the pointer p will be a[4]

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

    Fried my brain. Good night.

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

    Sir ans is
    Base add a[0]+2*4
    And
    Index 2

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

    Index = a[4]
    after p = p + 2

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

    Thanks for such great explanation ....

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

    6:49 ans is 4

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

    Initially p have &a [2] and after p=p+2 address will be shift two index right so ans is &a [4]

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

    Amazing explanation.

  • @MuhammadAbdullah-wx1ev
    @MuhammadAbdullah-wx1ev Год назад

    here a[2] means third element so p+2 wil shift the pointer to the fifth element so the final answer will be p=&a[[4]

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

    saying p = &a[2] and after the operation p = p + 2 the answer will be p = &a[2 + 2] === p = &a[4]

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

    4th index or 5th element 4B base address then 1016

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

    answer p will point to the fourth elements so p=&a[4]

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

    You are Doing a great work❤️❤️

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

    P=&a [2] at 5th element of array

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

    Answer is: a[4]

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

    I think the answer is p=[a4]...Because pointer shifts 2 places in the right direction.

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

    p=p+2 -> &array[2]

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

    Century complete now second century on. Can we say 6:00 p+3*4=Base address+next Element*total byte of that element.

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

    pointer will point index 4 i,e 5th element of an array

  • @D-Coder440
    @D-Coder440 Год назад

    Thank You Soo Much

  • @akhil9967
    @akhil9967 3 года назад +1

    If initial address is 1000 then 1016 is the location that pointer points to.

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

    Answer is p = &a[4]

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

    i strongly suggest putting the speed at 0.75x it's so much easier to understand

  • @AshishKumar-rb1gw
    @AshishKumar-rb1gw 2 года назад

    Programming language is very good and practice with me and improve skills thinku you so much your practice white

  • @ALOKKUMAR-gb4vn
    @ALOKKUMAR-gb4vn 4 года назад

    Answer for homework problem:the pointer will point to index a[4] after performing..p=p+2

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

    6.26 answer is a[4]

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

    INDEX WILL BE : a[4]

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

    Thank you for this wonderful job. 😀

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

    ANS= a[4]

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

    of course - a[4]

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

    The index is 4.. And the memory location is 1016.... (Say 0 index has 1000 memory location)

  • @sr-sunny-raj
    @sr-sunny-raj 4 года назад

    index after operation will be -: 4.

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

    The index of the array will be a[4].

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

    The answer is: it points to the element of index 4.

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

    a[4] i.e 5th element !

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

    The index will be at the 5th elements of the array.

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

    The answer is a[4]. I love these videos a lot, they are quite explanatory. Thank you.

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

    it'll be the fifth element of the array , a[4]

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

    a[4],5th element of an array.

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

    please make a videos in sorting techniques and some more programs on patterns it is important they test us logical knowledge

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

    Pointer will point to a[4]

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

    the answer is &a[4] and the pointer is in fifth position

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

    4th index @5th element