Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 8 |
The following three ‘C’ language statements is equivalent to which single statement?
y=y+1;
z=x+y;
x=x+1
y=y+1;
z=x+y;
x=x+1
z = x + y + 2; | |
z = (x++) + (++y); | |
z = (x++) + (y++); | |
z = (x++) + (++y) + 1; |
Question 8 Explanation:
From the below statements
y=y+1;
z=x+y;
x=x+1
First statement: “y” value is incremented by 1
Second statement : that incremented value is added to x and stored into “z”
Third statement : “y” value is incremented by 1
z = (x++) + (++y);
X++ post-increment , so it will perform action which is addition and later the value of “x” is incremented .
++y pre-increment , here first value “y” is incremented and updated value is added to value x.
Finally the result will store into z.
The sequence of operations you can find from the below statements
z=x+y; //z = x + (++y)
x=x+1 //z = (x++) + (++y)
y=y+1;
z=x+y;
x=x+1
First statement: “y” value is incremented by 1
Second statement : that incremented value is added to x and stored into “z”
Third statement : “y” value is incremented by 1
z = (x++) + (++y);
X++ post-increment , so it will perform action which is addition and later the value of “x” is incremented .
++y pre-increment , here first value “y” is incremented and updated value is added to value x.
Finally the result will store into z.
The sequence of operations you can find from the below statements
z=x+y; //z = x + (++y)
x=x+1 //z = (x++) + (++y)
Correct Answer: B
Question 8 Explanation:
From the below statements
y=y+1;
z=x+y;
x=x+1
First statement: “y” value is incremented by 1
Second statement : that incremented value is added to x and stored into “z”
Third statement : “y” value is incremented by 1
z = (x++) + (++y);
X++ post-increment , so it will perform action which is addition and later the value of “x” is incremented .
++y pre-increment , here first value “y” is incremented and updated value is added to value x.
Finally the result will store into z.
The sequence of operations you can find from the below statements
z=x+y; //z = x + (++y)
x=x+1 //z = (x++) + (++y)
y=y+1;
z=x+y;
x=x+1
First statement: “y” value is incremented by 1
Second statement : that incremented value is added to x and stored into “z”
Third statement : “y” value is incremented by 1
z = (x++) + (++y);
X++ post-increment , so it will perform action which is addition and later the value of “x” is incremented .
++y pre-increment , here first value “y” is incremented and updated value is added to value x.
Finally the result will store into z.
The sequence of operations you can find from the below statements
z=x+y; //z = x + (++y)
x=x+1 //z = (x++) + (++y)
Subscribe
Login
0 Comments