Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > diff bt postfix and prefix unary

Reply
Thread Tools

diff bt postfix and prefix unary

 
 
shan
Guest
Posts: n/a
 
      10-10-2005
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.

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      10-10-2005
"shan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      10-10-2005
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?"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee Perl Misc 32 10-11-2011 09:35 PM
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee Java 30 06-16-2007 05:57 PM
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee Python 30 06-16-2007 05:57 PM
Ordinary unary function to STL adaptable unary predicate how? SpOiLeR C++ 10 10-19-2005 01:18 PM
Prefix/postfix ops -- concept question Sergey C++ 6 04-01-2005 06:14 PM



Advertisments