Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
5.1k views
in Introduction to C++ by (49.1k points)
closed by

Evaluate the following C++ expressions where x, y, z are integers and m, n are floating point numbers. The value of x = 5, y = 4 and m = 2.5;

1. n = x + y / x; 

2. z = m * x + y; 

3. z = (x++) * m + x;

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

1. n = x + y / x;

= 5 + 4/5

= 5 + 0 (both x and y are int type. Therefore only integer part of quotient is considered)

= 5

2. z = m * x + y;

= 2.5 * 5 + 4 (m is float type, so x value is promoted to float [implicit conversion])

= 12.5 + 4 ‘

= 16 (2 is int type. So ‘.2’ , the fractional part is discarded)

3. z = (x++) * m + x;

= 5*2.5 + x

= 12.5 + 5

= 18 (z is int type, therefore the fractional part is removed, x is incremented after the addition)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...