Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 3 of 3
Thread: Arithmetic Operation Problem

09242011, 09:32 AM #1
 Join Date
 Sep 2010
 Posts
 27
 Thanks
 2
 Thanked 0 Times in 0 Posts
Arithmetic Operation Problem
hello Every one,
Today my problem is much complex for me, I am so confused why is this happening;
The problem is
if i have a = 2;
********** In C Language **********
and i perform
i = a++ + ++a + a + a + ++a;
then result is = 15
i = a++ + ++a + a + a;
then result is = 8
************ In Java Language ************
i = a++ + ++a + a + a + ++a;
then result is = 15
i = a++ + ++a + a + a;
then result is = 12
I don't know why is this happening, what is the reasion, I am performing the same operation but the result is different.
Please give me the detail description about this.
Thank You.
09242011, 07:03 PM
#2
 Join Date
 Sep 2011
 Posts
 45
 Thanks
 1
 Thanked 6 Times in 6 Posts
thats interseting,
make sure you that the initial value of a is the same in java and in c
try to divide it with brackets
i = (a++) + (++a) + (a) + (a);
and see if that makes a difference
09252011, 08:11 AM
#3
 Join Date
 Sep 2010
 Posts
 27
 Thanks
 2
 Thanked 0 Times in 0 Posts
Thanks for your reply chris0.
But the problem is same as it is yet.
for the java the program is
public class test {
public static void main(String ar[]) {
int a=2,j=0,k=0;
j = a++ + ++a + a + a + ++a;
k = a++ + ++a + a + a;
System.out.println("The value of j = " + j + " and the value of k = " + k);
}
}
then the result is
The value of j = 15 and the value of k = 12
Also if i seperate all of them with parenthesis like you told (a++) then the
result is same.
for c the program is
int main(void)
{
int a=2,j=0,k=0;
clrscr();
j = a++ + ++a + a + a + ++a;
k = a++ + ++a + a + a;
printf("The value of j = %d and the value of k = %d", j,k);
getch();
return 0;
}
then the result is
The value of j = 15 and the value of k =8
I used parenthesis Alos, but nothing happened.
Please give me the detail description about this problem.
thank you.