473,289 Members | 1,729 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,289 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 2231
"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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.