GeekInterview.com
Series: Subject: Topic:
Question: 120 of 126

int z;
int x = 5;
int y = -10;
int a = 4;
int b = 2;
z = x++ - --y * b /a;
What number will z in the sample code above contains

A. 5
B. 6
C. 10
D. 11

Asked by: Interview Candidate | Asked on: Jul 25th, 2005
Showing Answers 1 - 6 of 6 Answers
Vijaya Bhaskar M

Answered On : Jul 24th, 2005

Here the evaluation of expression starts from right side of the statement. so all variables are of type integer..so the b/a which is float result, so it will be taken as zero. and finally we will get the answer as 10

Yes  1 User has rated as useful.
  
Login to rate this answer.
umesh_singh

Answered On : Mar 26th, 2007

View all answers by umesh_singh

Execution starts from right hand side  since * and / has higher priority1) so b/a(of type int)=2/4=02)--y * (b/a)  =03)x++ is post incrementer so answer is                                                                5

Yes  1 User has rated as useful.
  
Login to rate this answer.
iliana

Answered On : Jan 27th, 2011

View all answers by iliana

Z=5++ - -- -10*2/4z=5++ - --  -20/4z=5++ - --   - 5z=6 - -4z=10

Yes  1 User has rated as useful.
  
Login to rate this answer.
prititripathi

Answered On : Feb 20th, 2011

View all answers by prititripathi

Since b/a =0 so all term except x++ become 0 and coz of precedence rule first value of x is assing in z then incerementso value of z is 5Ans a

  
Login to rate this answer.
DESTINY

Answered On : Sep 21st, 2012

A. 5

  
Login to rate this answer.
mahesh sanadya

Answered On : May 26th, 2013

10

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.