473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

diff bt postfix and prefix unary

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
2 2235
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sergey | last post by:
Hello! Could anybody be kind enough to explain this concept? Why C++ make two ops for prefix and postfix ++ operator? As I guess, it is possible to implement both cases via sole prefix...
2
by: Christian Christmann | last post by:
Hi, is there a difference in terms of efficiency when using a prefix "++x;" instead of a postfix "x++;"? Thanks Chris
8
by: lovecreatesbeauty | last post by:
Hello experts, Why can this difference between prefix increment/decrement and postfix increment/decrement reside in built-in operators for built-in data types? Thanks. // test.cpp // //...
98
by: jrefactors | last post by:
I heard people saying prefix increment is faster than postfix incerement, but I don't know what's the difference. They both are i = i+1. i++ ++i Please advise. thanks!!
19
by: Rajesh S R | last post by:
Consider the following code: int main() { struct name { long a; int b; long c; }s={3,4,5},*p; p=&s;
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
8
by: subramanian100in | last post by:
Consider int i = 10; Why do we say that ++i yields an Lvalue and i++ yields an Rvalue ? I thought both these expressions yield only values. I am unable to understand the difference
2
by: swapnaoe | last post by:
Hi, In http://elearning.embnet.org/file.php/43/ctutorial/Postfix-and-prefix----and---.html I read about postfix and prefix unary operators. It said " If the increment or decrement operator is...
2
by: puzzlecracker | last post by:
How can we implement operator ++ as postfix in prefix? thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.