By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

diff bt postfix and prefix unary

P: n/a
Hi to everybody,

I am begginer in C programming language.
My simple doubt is the difference between postfix & prefix unary
operator plus.
(i.e) i++ and ++i .

plz give me an example program with output.

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"shan" <sr**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi to everybody,

I am begginer in C programming language.
My simple doubt is the difference between postfix & prefix unary
operator plus.
(i.e) i++ and ++i .

plz give me an example program with output.


The value of a prefix increment expression is the
value after the increment.

The value of a postfix increment expression is the
value before the increment.

#include <stdio.h>

int main()
{
int pre = 1;
int post = 1;
/* prints 2 1 */
printf("++pre == %d post++ == %d\n", ++pre, post++);
/* prints 2 2 */
printf(" pre == %d post == %d\n", pre, post);
return 0;
}

This is very fundamental C. Which texbook(s) are you
reading which don't explain this?

-Mike
Nov 15 '05 #2

P: n/a
shan wrote:
Hi to everybody,

I am begginer in C programming language.
My simple doubt is the difference between postfix & prefix unary
operator plus.
(i.e) i++ and ++i .
This should be explained in any decent introductory C book.

`i++` returns the current value of `i`. `++i` returns one more than
the current value of `i`. Both eventually [1] increment `i`.
plz give me an example program with output.


Oh, /please/. /You/ write an example program for this. If you can't,
you're not ready for the ++ operators yet.

[1] By the next sequence point. Often a `;`.

--
Chris "electric hedgehog" Dollin
"I know three kinds: hot, cool, and what-time-does-the-tune-start?"
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.