Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}

Answers were Sorted based on User's Feedback



main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / 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

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / mahi

x=55
y=57

Is This Answer Correct ?    0 Yes 0 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / sanjev kumar sasode

56 93 (ANSI)
57 94 (Turbo C)

Is This Answer Correct ?    0 Yes 0 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / vijay

56
93

Is This Answer Correct ?    0 Yes 0 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / muhammad abdullah

#include<stdio.h>
#include<conio.h>
void main()
{
int x=20,y=35; (comment)//We delcare two variables and initialize them.
clrscr();
x=y++ + x++; (comment) /*As increment operator increases one in the value of variable.The value
of y is 35 and after increment of 1, the value of y will be 36.The value of
x=20 and after increment of 1, the value of x will be 21.Arithmetic operator
(+) adds both the values(36+21=57).So, the value of x=57.*/


y=++y + ++x; (comment) /*The value of y is 35.Due to increment operator the value of
y becomes 36.And we have ever got the value of x as it is x=57. Now,increment
operator add 1 in the value of x and the value of x will be 58.By adding
(36+58=94) we got the final value of y=94.*/
printf("The value of x=%d
The value of y=%d
",x,y);
getch();
}

Is This Answer Correct ?    0 Yes 0 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / ruchi

Answer is 57 and 94
bcoz precedence of the ++ operator is more than + operator
so y++ and x++ will be evaluated first before addition so
y++ will be 36 and x++ will be 21 after that 36 + 21 = 57
similar reasoning for y = ++y + ++x

Is This Answer Correct ?    8 Yes 9 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / deepak

57 94

Is This Answer Correct ?    3 Yes 4 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / arif shaik

main()
{
int x=20,y=35;
x=y++ + x++;//x=(y+1) + (x+1) here y=35,x=21
//x=36 + 21 = 57
//x=57 ;here previous x=21 is overwritten by 57
y=++y + ++x;//y=(1+y) + (1+x) here y=35, x=58 bcoz y
value refers y's initial address which contain 35 then
//y=(1+35) + (1+57)=36+58= 94
printf("%d %d\n",x,y);
}

Output:

57 94

Is This Answer Correct ?    2 Yes 3 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / s mahesh babu

56 and 93....

why bcz..... x=y++ + x++; in this expression xy values are post increment mean .. value not change so x=20+35-->55;

in next expression y=++y + ++x;...... so y & x pre increment ... here y=37+56.... 93

Is This Answer Correct ?    0 Yes 1 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Answer / aru

x=55
y=92
ie; x= 35 + 20
ie; x=55;
then y= 56 +36
ie; y=99

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

What are identifiers c?

0 Answers  


What are function pointers? Provide an example.

1 Answers  


tell me the full form of c?

2 Answers  


why the execution starts from main function

9 Answers  


What is the purpose of void pointer?

0 Answers  


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

2 Answers   Aricent, Manipal University,


program to find the roots of a quardratic equation

1 Answers  


how to set Nth bit of a variable?

1 Answers  


What is declaration and definition in c?

0 Answers  


Why is a semicolon (;) put at the end of every program statement?

0 Answers  


The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.

0 Answers   Microsoft,


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

0 Answers  


Categories