Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

A simple doubt in C !

Status
Not open for further replies.

truebs

Full Member level 5
Full Member level 5
Joined
Jan 21, 2005
Messages
310
Helped
22
Reputation
44
Reaction score
4
Trophy points
1,298
Location
Asia
Activity points
2,980
Hi,

We all know that for x=2

y = ++x ; y becomes 3
y = x++ ; y becomes 2 and x becomes 3 in both cases.

But as per rule of precendance... ++ operator has higher priority than = operator.
Then as per precendance .. y should become 3 in both the cases owing to higher precendance to ++ than =.

But it doesn't happen , why ? What is the possible bug or behavior of compiler ?

Thanks ..
 

"y = x++" means increment x after evaluating the expression.

So in this case, the expression is evaluated while x still equals 2, thus setting y to 2, and then after that evaluation is finished, x is incremented.
 

That's correct. Order of execution and precedence are two different, independent things.
 

I totally agree with lambtron and echo47, ++X and X++ are two different things.
Maybe if your code was:
++X;
X++;
Then there won’t be much difference but since you added an “=” to the expiration they will have two different effects.
 

hi,

in this statement:

x = *buf++;

means that x equals to *buf but for the next case buf points to next adress in memory.

if you write;

x = *(buf++);

x equals to the value in adress (buf+1),

that is the trick!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top