1.1 Assume that the variables a, b ,c, l and j are initialized as shown in the following code fragment. What is the value of each variable after these statements are executed?(Please provide explanations) Int 1 =5 , J=2 , double a = 6 , b, c a) b =++l-j—, b) J =(int) b/2, c) a = + =b /J ,
ANSWER:-
NOTE: c) a = + =b /J ; this wrong so i considered as a =+b/J;
a) b =++l-j—;
#include <iostream>
using namespace std;
int main() {
int l=5 , J=2;
double a=6,b,c; // default value of b,c is 0
++l-J--; // value of l will be 6 after increment of 1
and value of J will be 1 after decrement of 1
J =(int) b/2; // default value of b is 0 so 0/2=0
means value of J will be 0
a =+b/J; // 6+0/0= nan because 0/0 is arithmetic
exception so give nan
cout<<a<<" "<<b<<"
"<<c<<" "<<l<<" "<<J;
return 0;
}
so final value of all variables are :
a=-nan
b=0
c=0
J=6
l=0
// If any doubt please comment
Get Answers For Free
Most questions answered within 1 hours.