main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
Answer Posted / chalimar
Many of these answers depend on the results from Microsoft compiler, but I do not believe Microsoft complies with the C Standard. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
For example, in the expression x = y++ + x++;
here is Microsoft's assembler output:
mov eax, DWORD PTR _y$[ebp]
add eax, DWORD PTR _x$[ebp]
mov DWORD PTR _x$[ebp], eax
mov ecx, DWORD PTR _x$[ebp]
add ecx, 1 <<----------
mov DWORD PTR _x$[ebp], ecx <<----------
mov edx, DWORD PTR _y$[ebp]
add edx, 1
mov DWORD PTR _y$[ebp], edx
As some here have noted, Microsoft computes the expression, assigns to the lvalue, then does the post increment, X++. This does not seem to comply with the standard, which requires:
6.5.2.4 Postfix increment and decrement operators
... 2 The result of the postfix ++ operator is the value of the operand. After the result is obtained, the value of the operand is incremented. (That is, the value 1 of the appropriate type is added to it.) ... The side effect of updating the stored value of the operand shall occur between
the previous and the next sequence point.
Sequence points are an important aspect of a C program. In the Question, Microsoft does not resolve the postfix statement until after the "=" assignment, a situation that I view as a violation of the SEQUENCE POINT rule:
5.1.2.3 Program execution
...
2 ... Evaluation of an expression may produce side effects. At certain specified points in the execution sequence called sequence points, all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place. (A summary of the sequence points is given in annex C.)
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
Which built-in library function can be used to match a patter from the string?
Describe the header file and its usage in c programming?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
hi any body pls give me company name interview conduct "c" language only
What is the use of define in c?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
all c language question
Why we use void main in c?
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
What are the different types of errors?
What are c identifiers?
What is the size of array float a(10)?
what do u mean by Direct access files? then can u explain about Direct Access Files?
Why is c so important?