C_77 Pointers in C- part 7 | Pointer Arithmetic (Increment/Decrement) program
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
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
I guess 2,3 and garbage value bro..
@@flames_tech no, because he set *p=a[3] ! his result is true !
@@nguyendinhbac7165 but ma'am changed it to a[2] later
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❤
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☠️😅
14:59 answer is garbage value,3,2
Next one answer is
Segmentation fault
Correct aa bro
@@nikhilpragada1562 next ans will be 1012 1012 1012
The teacher's lectures are amazing! greetings from Vietnam !
p++ pahle print kro phir increment kro
++p pahle increment kro phir print kro
Thanks my teacher for everything ❤️🌹I understood this lesson after I have saw your episode
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....
2:15 lecture starts
Jenny the Robot
🤖
😂
So true 😂
Yes
Omggg 💯 💯 💯 💞
The answer is garbage value, 3, 2;
Youve made pointers so easy mum;
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
Thanks dude
thanks
Wish to present before you &thank you from bottom of my heart.💜
from bangladesh
Garage,3,2
At 11:29 it should be 3,2 as associativity is from left to right .
I too have that doubt
Associativity is from right to left, (
And answer is also correct, it would be 2 3
@@SN-edits4u my compiler returned 3,2. Can you please explain why?
#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
11:06
printf("%d %d",*p++ ,*p++);
it is undefined behaviour. my compiler(visual studio 2019) returns 3 -3 for example.
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.
Smile while closing session is awesome mam❤❤❤😊😊😊
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.
Same iam getting
Can u pls tell in which complier u are performing programs?
It is post increment associativity is from left to right
In pre-increment associativity is from right to left
See 17:40
Actually different compilers have different order of evaluation of printf statement
Generally it is right to left
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 🙏🙏
hello mam, the last one is showing only 1 1 1. don`t get, please help.
Aaj hi padna ka mood aya
Aaj hi a topic samajhna tha
Aur
Aaj hi aapne upload kardiya
😂acha tha na phir tu
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
Exactly
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.
Isn't it 2,3,garbage value?
@@33_amit okay
Ok but why in the case printf("%d %d",*p++, *p++); it displays result on the other way ?
yeah I know but because 0 WAS the garbage value for me for instance@@33_amit
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.
#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]
Thank you so much this video cleared my all confusions ❤️❤️
Thanku mam.... For explaining things... So simply.. 😊✨💐.....
Your every video is very clear mam. Thanks for your understandable lecture ☺️
1st ans is garbage value,3,2
ma'am but post increment operator ki associativity to left to right hena ??
Mam has confused at many points
Yes
Mam
please do lecture on Object oriented Progming in c++
My favorite computer language is c++
@@sujathanarayana2286 Do you know this language very well?
your each video is very clear mam
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 ..........
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
Thanks a lot Mam for this lecture!!!
Ma'am.When will the classes of C++ start
yes mam please make questions after completing the lecture of C .
Best teacher ❤️
output is
some random number
3
2
Me jee aspirant hu mujhe ye subject Ghanta nhi pata par aap bohot cute ho
Thanku jenny
thank you my dear mem 🙏, 🙏🙏🙏🙏🙏🙏🙏😍
Thank you so much mam!!❤️❤️
Good lecture but unnecessary lagging,like there is 7 lecture +2 lecture for pointers ,null void pointers with average video length of 20 min😢
So what's the problem ?
17:41 mam i am getting output as 3 2 why so mam??
Please please make videos on DSA placement specific questions??
be part of subject madam attracted my attention more 🥰
my compiler is following associativity from left to right. I don't know why it is so
Best lecture your lovely student ❤️❤️❤️
Hi
Mam please make a video on String in C programming.
Mam pls make vedios on dynamic memory allocation
#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 .
👏
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.
Great explanation 🥳
Thank you mam your lecture is Very Lovely 😍🌹🌹
CAT 👍💯🥰 keep more vedio
Mam lec 72 is missing from play list
Pointer and arthematics are different
Thanks for your efforts mam
Nyc sinha
Thankyou Jenny!! You explained it very well!!
Spreading knowledge is very usefull to all of us thanku sis
Thankyou Mam
Is it possible to make GUI, using C library entirely?
answer mila to mujhe bhi batana
if you get the answer let me know
for post decrement/increment associativity is left to right, but valuating from right to left . anyone know why
because precedence of post increment/decrement higher than the operator *( asterisk)
@@Rishabh11_12 so we should move from left to right but why mam said right to left
Yes I too have a doubt @Rishabh is saying correct
printf("%d",*p++); -> output is 3 , 2 it is will correct ouput maam
14.3 output- any garbage value,3,2...
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 :(((
It is because of the property precedence. I two things have same Associtivity then prefedence comes into picture
in c ++ pointer how creat in programming...
*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 .
in my compiler it is right to left
Please you can tell the c++ course also naa mam🙏
Me too.
i am coplitely understand look your lecture
Well said madam zi
Is it possible to use the increment and decrement operators in for loop to print the array ?
yes i try
printf("%d %d %d
", *p++,*p++,*p++);
Mam this code shows undefined. It's not good idea to use undefined code like this one
In my here also.
Could you please tell me the gate syllabus for csbs please
brilliant explanation
It is right, yha it's taken
Thank you ❤,
Mam is so beautiful
10:58 ma'am its undefined behavior wright ??
mam, i am getting like 4011434 something same code which I have written while *--p
output is
garbage value, 3 , 2
Crt
2,3,garbage value
in that question --(*p) , (*p)++ , ++(*p) i am getting 686868 values . any body pls help
It is coding process right way
Maan big fan of you mam
Make a video on how multidimensional array acts as a pointer when used as formal argument for a function
Right, madam zi
Program results are not found
Ma'am
make a video Job's on without coding and programming.
You don't take a bractet in printf statement
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 ?
❤️❤️👍
I love u mam💙💙
Mam can you please make video's in hindi
The answer is
garbage value, 3 , 2
end of the program!
🔥🔥🔥
What is the size of int variable is it 2bytes or 4bytes
It depends on the operating system and the compiler bt mostly jenny use 4bytes to teach.
finally I came here for thinking about my crush
Padhai likhai karo IAS bano🤣🤣
@@technicalspider2547 yes bro but I really want her
@jayanth rao why
@@Dhakarey_G because
This is not any crush or romance channel
👍👍