Can anybody please explain me that, why is the output of this program - 7 7 9 49 ??? Please give me a somewhat detailed explanation.... Thanks. # define PRODUCT(x) (x*x) int main() { int i=3,j,k,l; j = PRODUCT(i+1); k = PRODUCT(i++); l = PRODUCT(++i); printf("%d %d %d %d",i,j,k,l); Code (markup):
homework? I think the point is for you to mess about with it and understand what the i+1, i++, ++1 operations are doing.
Firstly, No Homework.Secondly, Yea i pretty much know how i+1, I++, etc works... i think i am unable to get how the operator expands.
I don't know C but I'd have thought the answers would be 5, 16, 9, 16 to find out what is going out repeat the printf between operations to see how the numbers are being manipulated
You aren't exactly right about that. Your code should work fine but it doesn't. I think that the problem is in the definition of PRODUCT(). Try defining it it in the regular way you define a function: int Product(int x) {...} Code (markup): not with #DEFINE.
Hi! You can imagine i++ and ++i as functions that take i as parameter and return some value. i++ returns i and then increments i ++i increments i and returns new value
Listen to Ultrabooked. You may understand ++i, but you evidently don;'t understand how it works in a define.