I hav one doubt regarding post decriment,the code in c is as follows.............

void main()
{
clrscr();
while(i--!=6)
i=i+2;
printf("%d\n",i);
getch();
}

I know the output is 5, but i read in a book dat the post incriment or decrement operators are evaluated after reaching semicolon(;).....but in while condition,the ondition fails so it wont execute the next line so, directly reaches printf.Till now there is no semicolon still the i value is decresed......wts da reason...can u sugest me..?

Thanks & Regards.

Recommended Answers

All 2 Replies

If you want help you must to fix your code. i is undefined and uninitialised. There are more problems with your code but first fix and beautify it.

Wow.

void main()  - don't use void main. main() returns an int.
{
  clrscr();
  while(i--!=6)      - where is i set to some intitial value?
      i=i+2;           - this is the end of the while loop 
                              I think you are missing {} to make a while block?
   printf("%d\n",i);
   getch();
}

You do realize that your while loop subtracts then adds to the same variable, essentially in the same statement. Eeeek...

Back up.

What are you trying to do?

commented: andor agrees +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.