473,654 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is *ptr++ equivalent to *(ptr++)

Is *ptr++ equivalent to *(ptr++) ?

Nov 15 '05 #1
27 6667
Yes you are right.

Nov 15 '05 #2
ju**********@ya hoo.co.in wrote:
Is *ptr++ equivalent to *(ptr++) ?


Yes. In each case, the associativity is right-to-left and, in each case, the
value seen by * is the old value of ptr, not the new value that it will
have when ++ has completed its work.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #3


ju**********@ya hoo.co.in wrote:
Is *ptr++ equivalent to *(ptr++) ?


yes it is correct....
one more

++*ptr == (*ptr)++

Nov 15 '05 #4
Richard Heathfield <in*****@addres s.co.uk.invalid > wrote:
ju**********@ya hoo.co.in wrote:
Is *ptr++ equivalent to *(ptr++) ?
Yes. In each case, the associativity is right-to-left and, in each case, the


I don't think "associativ ity" is the right word here, as they are
unary operators. "Precedence " is more appropriate, I think.
value seen by * is the old value of ptr, not the new value that it will
have when ++ has completed its work.

There's a rule of thumb for unary operators in C, first you read ones
to the right, then ones to the left (unless, of cource, paretheses
override this).

A couple of (non-trivial) examples:
*p++
++p[i];
*p[i]
&a[i]
++p->m
(type*)p->m
*p()

(But I haven't really made sure that it always works; and `sizeof' is
special.)

--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 15 '05 #5
ra***********@g mail.com wrote:


ju**********@ya hoo.co.in wrote:
Is *ptr++ equivalent to *(ptr++) ?


yes it is correct....
one more

++*ptr == (*ptr)++


I hardly think so.

--
Chris "electric hedgehog" Dollin
It's called *extreme* programming, not *stupid* programming.
Nov 15 '05 #6
Yes. See the details here:
http://msdn.microsoft.com/library/de....operators.asp
(google with "operator precedence" and "left to right" and "right to left"
for more lists)

Like you can see in the list, the post-increment operator will be executed
first, if there are no brackets.

The associativity for the indirection operator is right to left and for the
post-increment operator left to right. But for this example this is not of
any importance.

Eric
<ju**********@y ahoo.co.in> wrote in message
news:11******** ************@g4 3g2000cwa.googl egroups.com...
Is *ptr++ equivalent to *(ptr++) ?

Nov 15 '05 #7


Chris Dollin wrote:
ra***********@g mail.com wrote:


ju**********@ya hoo.co.in wrote:
Is *ptr++ equivalent to *(ptr++) ?


yes it is correct....
one more

++*ptr == (*ptr)++


I hardly think so.


The two constructs are equivalent in the following scenarios:

int *ptr = ...;
int i;

(void)++*ptr;
(void)(*ptr)++;

However, their behaviour is not the same when used like this:

i = (*ptr)++;
i = ++*ptr;

--
Vijay Kumar R. Zanvar
Home Page - http://geocities.com/vijoeyz/

Nov 15 '05 #8
Vijay Kumar R. Zanvar wrote:


Chris Dollin wrote:
ra***********@g mail.com wrote:
>
>
> ju**********@ya hoo.co.in wrote:
>> Is *ptr++ equivalent to *(ptr++) ?
>
> yes it is correct....
> one more
>
> ++*ptr == (*ptr)++


I hardly think so.


The two constructs are equivalent in the following scenarios:

int *ptr = ...;
int i;

(void)++*ptr;
(void)(*ptr)++;

However, their behaviour is not the same when used like this:

i = (*ptr)++;
i = ++*ptr;


Hence, they are not equivalent; you can't just use one in place
of the other.

--
Chris "electric hedgehog" Dollin
It's called *extreme* programming, not *stupid* programming.
Nov 15 '05 #9


Chris Dollin wrote:
Vijay Kumar R. Zanvar wrote:


Chris Dollin wrote:
ra***********@g mail.com wrote:

>
>
> ju**********@ya hoo.co.in wrote:
>> Is *ptr++ equivalent to *(ptr++) ?

[..]
Hence, they are not equivalent; you can't just use one in place
of the other.

Yes, you're quite correct. But for a learner, he/she must know the
difference. Practically, these two construct should not be
interchanged.
--
Chris "electric hedgehog" Dollin
It's called *extreme* programming, not *stupid* programming.


Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1693
by: G Fernandes | last post by:
Hello fellow C-goers, Comparisons of pointer variables to 0 are automatically converted to comparisons to NULL (which can be represented at the bit level but something non-zero). But how about using !ptr or ptr in test conditions (of loops, if or ?:) ? For example:
19
14899
by: Jason | last post by:
Hello, could someone explain the difference to me inbetween: *ptr++ and ++*ptr Thankx a lot.. Jason.
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.