C Programming Tutorial 9 Post Increment part 2

preview_player
Показать описание
post Increment operator is used to increment the current value of variable by adding integer 1.

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :
Рекомендации по теме
Комментарии
Автор

if u want increment 'i' then do directly "i++;" instead of "i=i++;" this will only force 'i' equal to 'i'
Hope this clears doubt, although in turbo C and Dev C++ its still a mystery, pls correct me if I'm wrong

iam_moin_shaik
Автор

#include <stdio.h>
#include <stdlib.h>

int main()
{

int i = 1;
int j = 1;
int y;
int z;
y=++i;
z=j++;


printf("%d %d \n", y, z);
return 0;
}

This returns y=2 and z=1. My thoughts are it seems like any time in code that you say y= a variable like i, you are going to want to use pre-increment because post increment will not update y in a useful manner (or z in this case) If it doesn't matter the order you change the value of y (or z), then you could use post-increment, but it would seem not worth it, it could cause problems in code later on if someone were in the habit of using post-increment.

FingersBlazin
Автор

Correct explanation: This is an example of undefined behavior in C, the result can be anything, not only 1. Please read the C standard first.

programmertotherescue
Автор

Bro i dont understand why you add again i=temp; you clear my clarification

Rajaking
Автор

The output of mystery and solved mystery was same and that is 1

rakshithkumarna
Автор

good explanation, the temp example made it clearer

ahmedaj
Автор

sir i did not understand the temp example please, get me clarified

Kaivalya-ch
Автор

sir ye wala aur iske pahle wala video nahi samaj aaya...so pls try to simplify these 2 YOU

adarshtapariya
Автор

But sir Surprisingly I'm getting 2 in turbo c++, although 1 is devC++ 😂

bitanchakraborty
Автор

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i = 1;
int temp;
temp = i;
++i;
i=temp;



printf("%d \n", i);
return 0;
}

This returns a value of 1 also... I noticed if I put in temp=i I always get a value of 2 as well. Curious!

FingersBlazin
Автор

if we try to access the memory location of "i" at various levels of execution the location doesn't get changed. My turbo c++ compiler is not accepting with the above code. it gives 2 as result..
if something is wrong with me.. you are pleased to correct me..

vamshiarakatla