Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

#include // hand trace practice int main(void) { // some have initial values int num1 = 8, num2 = 6; int sum, result; int trash = -4; // some crazy calculations result = 4 * num1 - 26 / num2 % 3; sum = num1++ + --num2; trash -= sum + result; // display results printf("num1 %d num2 %d sum %d result %d trash %d", num1, num2, sum, result, trash); printf("\n\n"); return 0; } What are sum and result?

OpenStudy (anonymous):

compile and run it :-D http://codepad.org/ujqqgJTp

OpenStudy (anonymous):

ooh hand trace practice. so you weren't supposed to do what I just did :-P lets initialize the stuff \[num1 = 8\] \[num2 = 6\] \[trash = -4\] this one gets a little tricky, but if you are absolutely unsure, refer to the white book pages 52 to 53. And lo! *, /, and % all have the same precedence, and are left to right associative. *, %, and / have higher precedence that subtraction. I translated it to parens in the following expression: \[result = (4*num1) - ((26/num2)mod3)\] \[result = 32 - 1 = 31\] the prefix -- decrement operator decreases the value of num2 before the rest of the expression is calculated. \[num2 = 5\] num1 uses the same old value of num 1, which is 8 \[sum = 8 + 5 = 13\] the postfix ++ increment operator increments num1 after sum is assigned a value. \[num1 = 9\] the next one is straightforward \[trash = trash - (13 + 31) = -4 -44 = -48\] Therefore, you should get something like \[num1 = 9, num2 = 5, sum = 13, result = 31, trash = -48\]

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!