What is the value of Y1 if Y =7?
Y1= ++Y - Y++ + --Y
Answers
Answer:
Cisco Systems Interview Question for Software Engineer / Developers
cisco-systems-interview-questions0
of 0 votes
61
Answers
x = x++ + ++y;
y = ++x + ++y;
what are the values of x,y after these are executed ?
- Lively May 06, 2012 in United States | Report Duplicate | Flag |
Cisco Systems Software Engineer / Developer C
Email me when people comment.
Country: United States
More Questions from This Interview
Email me when people comment.
6
of 8 vote
x = x++ + ++y; (1)
y = ++x + ++y; (2)
In (1) this is the following operations to be done.
i) ++y
ii) x = x+y
iii) x ++
In (2) this is the following operations to be done.
i) x ++
ii) y++
iii) y = x + y
- Psycho May 07, 2012 | FlagReply
0
of 0 votes
i have a doubt .
the precedence of increment operator is higer than +,*,/ ,then before performing addition,The postfix and prefix operation is performed then then arithmetic operation.
in both cases i think the operations to be done are
i)++x
ii)y++
iii)y=x+y
- Rishabh June 12, 2015 | Flag
3
of 3 vote
What I can tell from the C standard, that in x = x++ + ... the value of x is getting modified twice within one sequence point. So it is Undefined Behaviour and the answer would vart depending upon the implementation of the compiler.
- Mukesh May 06, 2012 | FlagReply
1
of 1 vote
x will become x+y+3 & y will be x+2y+5
#include<stdio.h>
int main()
{
int x=5,y=15;
x= x++ + ++y;
y = ++x + ++y;
printf("%d %d",x,y);
return 0;
}
Output: 23 40
- Nishant Kumar September 05, 2012 | FlagReply
0
of 0 votes
don't know the answer
- prachi October 29, 2012 | Flag
0
of 0 votes
I get the output 22 39 for that same code.
- Anonymous January 13, 2016 | Flag
0
of 0 votes
Answer is 22,40
- Anonymous March 27, 2019 | Flag
0
of 0 votes
output shown by my computer is 22 and 39
- Anonymous August 02, 2019 | Flag
0
of 0 vote
when x = 1, y = 1, we got x = 5, y = 8 after that
- milo May 06, 2012 | FlagReply
0
of 0 votes
c++
- milo May 07, 2012 | Flag
0
of 0 votes
Hindi
- Anon August 13, 2012 | Flag
0
of 0 vote
What language?
- Anonymous May 07, 2012 | FlagReply
0
of 0 votes
Hindi
- Anon August 13, 2012 | Flag
0
of 0 vote
Undefined, will depend on compiler to compiler
- shani May 07, 2012 | FlagReply
0
of 0 vote
x=5 and y=8
- ric May 07, 2012 | FlagReply
0
of 0 vote
5,8 with following compiler.
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
- kiran May 08, 2012 | FlagReply
0
of 0 vote
Its UB (Undefined-Bahvior). value of x is being modified without any sequence-point in between. There is no way you can be sure of the value of x.
- arnuld May 11, 2012 | FlagReply
0
of 0 vote
I wrote the code and tested no matter what you do in both the cases x & y will be incremented first as they are closely bind to "++" and after they are incremented then only they are added, refer wiki for operator precedence.
if x = y = 0 initially, both cases will have answer 2,
if x = 1, y =2 then both cases will have answer 5.
- Anonymous May 19, 2012 | FlagReply
0
of 0 vote
#include<stdio.h>