Jump to content
ChetanaSforum

Recommended Posts

Hello,

can anyone tell the difference of these please...

a=i++.

when i =0, and printing a[0]=?

 

i=i++;

when i=3, and printing =?

 

please i need the difference....

 

rash

Share this post


Link to post
Share on other sites

Hello,

can anyone tell the difference of these please...

a=i++.

when i =0, and printing a[0]=?

 

i=i++;

when i=3, and printing =?

 

please i need the difference.... :)

 

rash

hello

 

in the first case of array first assignment takes place and the increment takes place once the assignment takes it will placed in meomory or array it is concerned with i and i increments to 1 but there is no assignment so then ans is 0

 

wheras in the second case first assignment and then increment takes place since i is the variable first i will be 3 during assignment and later it gets incremented so that i will change to 4

Share this post


Link to post
Share on other sites

Hello,

can anyone tell the difference of these please...

a=i++.

when i =0, and printing a[0]=?

 

i=i++;

when i=3, and printing =?

 

please i need the difference....

 

rash

Hi in both cases the final value is initial I itself

i.e a[0]=0 and i=3;

if it is ++i then i value is incremented before the operation that we perform,

if it is i++ then operation takes place first and then incremented

now after the intialization i contain

case 1: i=1;

case 2: i=4;

Share this post


Link to post
Share on other sites

According C standard a=i++ is undefined,where as a=i+1 is possiblebcoz in 1st condition we are trying to increment value of i twice in single statement, and some compilers does not show any error & the result is not predictable by us ,if u still hava doubt go through in TEST YOUR C SKILLS BY YASHWANTH .it gets clear

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×