hey all ! i am pragensh and joined today for follwoing reason
can you help me how this output came ?
x=3;
x-=--x-x--;
printf("x=%d",x);
here answer is coming as 1 how come ?
can you please help me to find the reason ? or
step wise explaination
3 3649
Putting two unary operations like that on the same line has undefined behavior, it's not ever a good idea. However, in your case, it looks like your compiler evaluates left to right. However, parenthesis come first. I substitute for x when I put it's value in parenthesis, i.e. --(3), (2)--, or (1).
x = 3;
x = x - (--x - x--)
x = x - (--(3) - x--)
x = x - (2 - x--)
x = x - (2 - (2)--)
x = x - (2 - 2)
x = (1) - 0
x = 1 - 0
x = 1
Putting two unary operations like that on the same line has undefined behavior, it's not ever a good idea. However, in your case, it looks like your compiler evaluates left to right. However, parenthesis come first. I substitute for x when I put it's value in parenthesis, i.e. --(3), (2)--, or (1).
x = 3;
x = x - (--x - x--)
x = x - (--(3) - x--)
x = x - (2 - x--)
x = x - (2 - (2)--)
x = x - (2 - 2)
x = (1) - 0
x = 1 - 0
x = 1
thank you sir but i am get back to you with some doubt regarding the same topic
sir i think this is how the steps will go,but can u explain me your logic in steps (1) & (2)
x = 3;
x = x - (--x - x--)
x = x - (--(3) - x--)
x = x - (2 - x--)
x = x - (2 - (2)--)
x = x - (2 - 1) /* (sir according to postfix operation) */ .. (1)
x = (2) - 1 (2)
x = 2-1
x = 1
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
//
//...
|
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!!
|
by: Anoob |
last post by:
Can we consider () unary operator when calling a function, in exps eq.
f(), ( 1 + 2). But when we call function f( 10 ) it is a binary
operator. Even if we pass f( 10, 20) as we are using ,...
|
by: shan |
last post by:
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...
|
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”....
|
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
|
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...
|
by: news.aioe.org |
last post by:
Is it possible to overload increment(++) and decrement(--) postfix and prefix
operators for primitive datatypes such as int, char, short, etc. in global scope
(vs as a class member function where...
|
by: puzzlecracker |
last post by:
How can we implement operator ++ as postfix in prefix?
thanks
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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: 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...
|
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 projectplanning, coding, testing,...
| | |