C_77 Pointers in C- part 7 | Pointer Arithmetic (Increment/Decrement) program

Sdílet
Vložit
  • čas přidán 10. 09. 2024
  • In this lecture we will discuss Pointer Arithmetic. How to perform Increment/Decrement with pointers.
    Best C Programming Tutorials: • Programming in C
    *********************************************
    Connect & Contact Me:
    Jenny's Lecture Hindi: / @jennyslectureshindi
    Facebook: / jennys-lectures-csit-n...
    Quora: www.quora.com/...
    Instagram: / jayantikhatrilamba
    Twitter: / khatrijenny
    Telegram Group Link: Jenny's Lectures
    telegram.me/je...
    *******************************************
    More Playlists:
    Programming in C Tutorials: • Programming in C
    C++ Tutorials for beginners: • Lec 1: How to Install ...
    Printing Pattern in C: • Printing Pattern Progr...
    Best Python Tutorials for Beginners: • Python - Basic to Advance
    Placement Series: • Placements Series
    Data Structures and Algorithms: https: • Data Structures and Al...
    Design and Analysis of Algorithms(DAA): • Design and Analysis of...
    Dynamic Programming: • Dynamic Programming
    Operating Systems tutorials: // • Operating Systems
    DBMS Tutorials: • DBMS (Database Managem...
    Tags:
    pointers in c, what is pointer, introduction to pointers in c
    #coding #strings #jennyslectures #cprogramming #clanguage
    #pointersinC
    #pointerarithmeticinC
    #jennyslectures

Komentáře • 200

  • @balkrishnabane1392
    @balkrishnabane1392 Před 2 lety +18

    13:59
    int a[]={3,2,67,0,56};
    int *p;
    p=&a[3];
    in increment decrement it has right to left precedence, So the 3rd (*--p) will be solved frst
    the 3rd *--p will decrement and then the value of p will be used for the next expression
    initial value for *p=a[3] = 0
    3rd. *--p = decrement to a[2] = 67
    2nd. *--p= decrement to a[1] = 2
    1st. *--p= decrement to a[0] = 3
    output:- 3 2 67

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

      I guess 2,3 and garbage value bro..

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

      @@flames_tech no, because he set *p=a[3] ! his result is true !

    • @helloworld2054
      @helloworld2054 Před rokem +2

      @@nguyendinhbac7165 but ma'am changed it to a[2] later

  • @andydufresne436
    @andydufresne436 Před měsícem +1

    16:04 printf ("%d %d", *p++ , *p++); // ABNORMALITY in this Code..
    The post - inc/dec has associativity , L -> R .
    But the result, shown seems to be executed from R -> L ('2 3' is output instead of '3 2').
    From chatgpt, "The order of evaluation, of function arguments is unspecified in C. It may vary with compilers."
    printf is a function and here each p++ may be an argument. Hence the variation in order.
    Conclusion : It's better to not use, more than 1 increment or decrement operator in a Single line of code , to avoid abnormal behaviour.
    By the way, Thanks Jenny for this amazing lecture series❤

    • @andydufresne436
      @andydufresne436 Před měsícem

      Also, I read that, arguments of printf are evaluated from Right to Left ⬅️ . But when I printed,
      printf("%d %p", *p++, p); // result= a[0] &a[1]
      printf("%d %p", *p, p++); // result= a[1] &a[0]
      It means, whatever the order is, argument with increment is executed at 1st, (for post-inc, the original value of the p is assigned for the ++ argument and then incremented for the next argument.
      for *p++, it is assigned with address of p and print a[0], Now p= &a[1], and it is printed in the place of p.
      for p++, it is assigned with address of a[0] and print a[0], Then p is incremented, p=&a[1] and *p = a[1] is printed.
      Conclusion again : Inc/dec operator itself is dangerous☠️😅

  • @rakshithcc5488
    @rakshithcc5488 Před 2 lety +33

    14:59 answer is garbage value,3,2

  • @nguyendinhbac7165
    @nguyendinhbac7165 Před 2 lety +15

    The teacher's lectures are amazing! greetings from Vietnam !

  • @amitprasadiitg2564
    @amitprasadiitg2564 Před 2 lety +18

    p++ pahle print kro phir increment kro
    ++p pahle increment kro phir print kro

  • @user-ft2qx3qj4v
    @user-ft2qx3qj4v Před 3 lety +14

    Thanks my teacher for everything ❤️🌹I understood this lesson after I have saw your episode

  • @sandepaganaresh969
    @sandepaganaresh969 Před 3 lety +10

    Thank u so much sister for spreading your knowledge... I like very much the way of your teaching... Keep support us and we will always support you sister... Thank u thank u so much....

  • @tanishaagarwal8497
    @tanishaagarwal8497 Před 2 lety +15

    2:15 lecture starts

  • @shivendra3019
    @shivendra3019 Před 3 lety +87

    Jenny the Robot

  • @devSackey
    @devSackey Před rokem +3

    The answer is garbage value, 3, 2;
    Youve made pointers so easy mum;

  • @741ibrahim2
    @741ibrahim2 Před 2 lety +19

    the basic difference between *p++ is here we are incrementing the adresses but in case of (*p)++ means we are incremwnting its value:
    eg:->
    int a[5]={50,1,-1,10,18};
    int *p=&a[4];
    printf("%d
    ",(*p)--);// ans= 18
    printf("%d
    ",*p);// ans=17
    in case of :->
    int a[5]={50,1,-1,10,18};
    int *p=&a[4];
    printf("%d
    ",*p--);// ans= 18
    printf("%d
    ",*p);// ans=10

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

    Wish to present before you &thank you from bottom of my heart.💜
    from bangladesh

  • @GoluSingh-og1zv
    @GoluSingh-og1zv Před 2 lety +10

    Garage,3,2

  • @yogeshchauhan9401
    @yogeshchauhan9401 Před rokem +7

    At 11:29 it should be 3,2 as associativity is from left to right .

    • @thilakparamasivan8409
      @thilakparamasivan8409 Před rokem +3

      I too have that doubt

    • @SN-edits4u
      @SN-edits4u Před rokem

      Associativity is from right to left, (

    • @SN-edits4u
      @SN-edits4u Před rokem

      And answer is also correct, it would be 2 3

    • @roxi-345
      @roxi-345 Před 8 měsíci

      @@SN-edits4u my compiler returned 3,2. Can you please explain why?

  • @maryannemuthoni5388
    @maryannemuthoni5388 Před 7 měsíci +5

    #include
    int main(void)
    {
    int a[] = {3, 2, 67, 0, 56};
    int *p = &a[3];
    printf("%d
    ", --(*p));
    printf("%d
    ", (*p)++);
    printf("%d
    ", ++(*p));
    return 0;
    }
    This will give -1, -1, 1
    In the first printf, *p value is 0 then with pre decrement it becomes -1
    In the second printf *p is -1 so it's -1++ which is post increment so -1 is printed but the actual value is now 0.
    In the third printf it's pretty increment so the 0 becomes 1

  • @marduktr
    @marduktr Před rokem +3

    11:06
    printf("%d %d",*p++ ,*p++);
    it is undefined behaviour. my compiler(visual studio 2019) returns 3 -3 for example.

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

    Ma'am can you start some coding from geeks for geeks, it will be a great help if you start placement series, from geeks for geeks, Hacker and leet codes.

  • @dudekuladastagiri7453
    @dudekuladastagiri7453 Před 8 měsíci +2

    Smile while closing session is awesome mam❤❤❤😊😊😊

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

    At 11:00
    When i run
    printf("%d %d",*p++,*p++);
    my output coming is. : 3 2
    But according to you it should be 2 3.

    • @Sheukh-j6m
      @Sheukh-j6m Před rokem

      Same iam getting

    • @gyanendarkaur2283
      @gyanendarkaur2283 Před rokem

      Can u pls tell in which complier u are performing programs?

    • @ourculture7079
      @ourculture7079 Před rokem

      It is post increment associativity is from left to right
      In pre-increment associativity is from right to left

    • @ananyaghosh6402
      @ananyaghosh6402 Před rokem

      See 17:40

    • @vaishnavigoswami5707
      @vaishnavigoswami5707 Před rokem

      Actually different compilers have different order of evaluation of printf statement
      Generally it is right to left

  • @NASICMEDIA
    @NASICMEDIA Před rokem +4

    Your explanation are so simple and easy to understand. I'm studying programming fundamentals and your videos helped me so much. Thank you very much 🙏🙏

  • @Gameplay-st7ve
    @Gameplay-st7ve Před 3 lety +5

    hello mam, the last one is showing only 1 1 1. don`t get, please help.

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

    Aaj hi padna ka mood aya
    Aaj hi a topic samajhna tha
    Aur
    Aaj hi aapne upload kardiya

  • @Raam1827
    @Raam1827 Před rokem +5

    Ma'am you said associativity of post increment and decrement is left to right and associativity of pre increment and decrement is right to left in your previous video of associativity video

  • @misturaojulari9707
    @misturaojulari9707 Před rokem +10

    The output of 14:13 will be garbage value, 3, 2
    Thank you so much for the explanations, before watching your videos to this point, I really felt dumb.

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

    thanks for the lecture im learning a lot thanks to you I have just a little concern on this topic on incrementation and deference that can happen , I don't know why on your computer is giving you this strange results.
    In a standard C environment, the expressions ++*p and *p++ are distinct and have different behaviors.
    ++*p is the pre-increment operator applied to the value pointed to by p. It increments the value before it is used in the expression. So if p points to 3, then ++*p increments 3 to 4, and 4 is the result used in any further expression.
    *p++ is the dereference operator applied to the value pointed to by p, followed by the post-increment operator applied to the pointer p itself. It dereferences the value (fetches the value 3 in this case) and then increments the pointer to point to the next element in the array after accessing the value. The result used in the expression is the original value before the pointer was incremented.

  • @maryannemuthoni5388
    @maryannemuthoni5388 Před 7 měsíci +1

    #include
    int main(void)
    {
    int a[] = {3, 2, 67, 0, 56};
    int *p = &a[3];
    printf("%d %d %d", *--p, *--p, *--p);
    return 0;
    }
    This will give 67, 2, 3
    Assosciativity is Right to left so the first *--p at the end is evaluated and since it's pre decrement p moves from holding the address of p[3] to p[2] so this prints the value 67, the next *--p moves from p holding address of p[2] to p[1] so value at p[1] which is 2 is printed. The last *--p moves p from holding address of p[1] to address of p[0]. It prints value 3 that is at p[0]

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

    Thank you so much this video cleared my all confusions ❤️❤️

  • @badalgugnani9876
    @badalgugnani9876 Před 9 měsíci +1

    Thanku mam.... For explaining things... So simply.. 😊✨💐.....

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

    Your every video is very clear mam. Thanks for your understandable lecture ☺️

  • @praveenthammishetti6342
    @praveenthammishetti6342 Před 2 měsíci +1

    1st ans is garbage value,3,2

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

    ma'am but post increment operator ki associativity to left to right hena ??

  • @bovaskurian1152
    @bovaskurian1152 Před 3 lety +6

    Mam
    please do lecture on Object oriented Progming in c++

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

    your each video is very clear mam

  • @zenistu__ff7524
    @zenistu__ff7524 Před rokem +2

    char ch =x;
    char *pch=&ch;
    printf(" uppercase is %c",*pch-32);
    output = X;
    according to what you said *pch should return x's address right ?
    or increment/decrement different from adding integers ??
    please clarify doubt ..........

    • @TUCSVIJAYASHARATHIS
      @TUCSVIJAYASHARATHIS Před rokem

      bro in the print statement u use that indirectionor dereference operator so only its given captial X i think so but i'm not sure about my answer are correct

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

    Thanks a lot Mam for this lecture!!!

  • @danishalam4405
    @danishalam4405 Před 3 lety +6

    Ma'am.When will the classes of C++ start

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

    yes mam please make questions after completing the lecture of C .

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

    Best teacher ❤️

  • @vanshikagarg7586
    @vanshikagarg7586 Před rokem +1

    output is
    some random number
    3
    2

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

    Me jee aspirant hu mujhe ye subject Ghanta nhi pata par aap bohot cute ho

  • @yogitelugugaming6730
    @yogitelugugaming6730 Před rokem +1

    Thanku jenny

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

    thank you my dear mem 🙏, 🙏🙏🙏🙏🙏🙏🙏😍

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

    Thank you so much mam!!❤️❤️

  • @rogue100
    @rogue100 Před 7 měsíci +1

    Good lecture but unnecessary lagging,like there is 7 lecture +2 lecture for pointers ,null void pointers with average video length of 20 min😢

  • @ummesalma6669
    @ummesalma6669 Před rokem +1

    17:41 mam i am getting output as 3 2 why so mam??

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

    Please please make videos on DSA placement specific questions??

  • @VivekVivek-hk6eo
    @VivekVivek-hk6eo Před rokem

    be part of subject madam attracted my attention more 🥰

  • @jaijaijaijai123
    @jaijaijaijai123 Před 3 dny

    my compiler is following associativity from left to right. I don't know why it is so

  • @VADLAMUDIRAMALAKSHMI-co5st

    Best lecture your lovely student ❤️❤️❤️

  • @ashishphaltankar
    @ashishphaltankar Před 3 lety +6

    Mam please make a video on String in C programming.

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

    Mam pls make vedios on dynamic memory allocation

  • @alexandertheuri444
    @alexandertheuri444 Před rokem +6

    #include
    int main()
    {
    int a[ ]={3, 2, 67, 0, 56};
    int *p=&a[0];
    printf("%d", ++*p);
    return 0;
    }
    out puts 4
    Would like to share this at 1st p prints 3 as the aesterick marks it at the base index Then increments the value which is 3 by 1 to out put 4 at the console .

    • @palanisamyj2315
      @palanisamyj2315 Před rokem

      👏

    • @andreamerlino7216
      @andreamerlino7216 Před 10 měsíci +1

      n a standard C environment, the expressions ++*p and *p++ are distinct and have different behaviors.
      ++*p is the pre-increment operator applied to the value pointed to by p. It increments the value before it is used in the expression. So if p points to 3, then ++*p increments 3 to 4, and 4 is the result used in any further expression.
      *p++ is the dereference operator applied to the value pointed to by p, followed by the post-increment operator applied to the pointer p itself. It dereferences the value (fetches the value 3 in this case) and then increments the pointer to point to the next element in the array after accessing the value. The result used in the expression is the original value before the pointer was incremented.

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

    Great explanation 🥳

  • @hydrapiyu449
    @hydrapiyu449 Před rokem

    Thank you mam your lecture is Very Lovely 😍🌹🌹

  • @pravin.rpravin.r9410
    @pravin.rpravin.r9410 Před 3 lety +2

    CAT 👍💯🥰 keep more vedio

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

    Mam lec 72 is missing from play list

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety +3

    Pointer and arthematics are different

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

    Thanks for your efforts mam

  • @sevestiansays9699
    @sevestiansays9699 Před rokem +1

    Thankyou Jenny!! You explained it very well!!

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

    Spreading knowledge is very usefull to all of us thanku sis

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

    Thankyou Mam

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

    Is it possible to make GUI, using C library entirely?

  • @Unknown-uo7yy
    @Unknown-uo7yy Před 2 lety +2

    for post decrement/increment associativity is left to right, but valuating from right to left . anyone know why

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

      because precedence of post increment/decrement higher than the operator *( asterisk)

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

      @@Rishabh11_12 so we should move from left to right but why mam said right to left

    • @adityadadhich3169
      @adityadadhich3169 Před rokem +2

      Yes I too have a doubt @Rishabh is saying correct

  • @vivekreddy111
    @vivekreddy111 Před 10 měsíci

    printf("%d",*p++); -> output is 3 , 2 it is will correct ouput maam

  • @user-oc7cr9gu6w
    @user-oc7cr9gu6w Před 2 lety +1

    14.3 output- any garbage value,3,2...

  • @charles-henriduclaumonty5066

    Maam printf("%d %d",*p++, *p++); why it reads from right to left in this line ? Even chatGPT not able to give me the answer :(((

    • @SPD114
      @SPD114 Před 9 měsíci

      It is because of the property precedence. I two things have same Associtivity then prefedence comes into picture

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

    in c ++ pointer how creat in programming...

  • @dinesh17999
    @dinesh17999 Před 2 lety

    *p++,*p++ for post increment associativity is left to right s
    we should go from left to right why mam said it is from right to left .

    • @simon-gh1pt
      @simon-gh1pt Před rokem

      in my compiler it is right to left

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

    Please you can tell the c++ course also naa mam🙏

  • @shiv23575
    @shiv23575 Před 2 lety

    i am coplitely understand look your lecture

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety +1

    Well said madam zi

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

    Is it possible to use the increment and decrement operators in for loop to print the array ?

  • @md.al-aminpatwoary3984

    printf("%d %d %d
    ", *p++,*p++,*p++);
    Mam this code shows undefined. It's not good idea to use undefined code like this one

  • @Guru-nz3sh
    @Guru-nz3sh Před 3 lety +1

    Could you please tell me the gate syllabus for csbs please

  • @nitul5092
    @nitul5092 Před rokem

    brilliant explanation

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety

    It is right, yha it's taken

  • @djihanelouali5744
    @djihanelouali5744 Před rokem

    Thank you ❤,

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

    Mam is so beautiful

  • @vikings.777
    @vikings.777 Před rokem

    10:58 ma'am its undefined behavior wright ??

  • @user-mo6dh7tv6m
    @user-mo6dh7tv6m Před rokem

    mam, i am getting like 4011434 something same code which I have written while *--p

  • @Avinashkumar-dy8bf
    @Avinashkumar-dy8bf Před 2 lety +2

    output is
    garbage value, 3 , 2

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

    2,3,garbage value

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

    in that question --(*p) , (*p)++ , ++(*p) i am getting 686868 values . any body pls help

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety

    It is coding process right way

  • @skshabana593
    @skshabana593 Před 3 lety

    Maan big fan of you mam

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

    Make a video on how multidimensional array acts as a pointer when used as formal argument for a function

  • @jatingupta7725
    @jatingupta7725 Před rokem

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety

    Right, madam zi

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety

    Program results are not found

  • @danthamravi5643
    @danthamravi5643 Před 3 lety

    Ma'am
    make a video Job's on without coding and programming.

  • @SravanKumar-uc6qt
    @SravanKumar-uc6qt Před 3 lety

    You don't take a bractet in printf statement

  • @vivekagarwal8585
    @vivekagarwal8585 Před 8 měsíci

    I wrote this program in visual studio
    #include
    #include
    int main()
    {
    int a[] = { 1,2,3,4,5 };
    int* p;
    p = a;
    //p = p + 4;
    printf("%d
    ", *p);
    printf("%d
    %d
    %d
    ", *++p, *++p, *++p);
    return 0;
    }
    Output is:
    1
    4
    4
    4
    It looks to me first it is incrementing the value p 3 times and the start printing.
    ----------------------------
    Same observation in pre-decrementing.
    ---------------------------
    Anything has been changed ?

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

    ❤️❤️👍

  • @shajeedmushkin6012
    @shajeedmushkin6012 Před 3 lety

    I love u mam💙💙

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

    Mam can you please make video's in hindi

  • @kasimshah7665
    @kasimshah7665 Před rokem +1

    The answer is
    garbage value, 3 , 2
    end of the program!

  • @VishalKumar-uu3xm
    @VishalKumar-uu3xm Před 2 lety +1

    🔥🔥🔥

  • @putchakayalasravanthi1530

    What is the size of int variable is it 2bytes or 4bytes

    • @jennychinyere5090
      @jennychinyere5090 Před rokem

      It depends on the operating system and the compiler bt mostly jenny use 4bytes to teach.

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

    finally I came here for thinking about my crush

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

    👍👍