1

I think I might be digging into this too deep but I am curious if there really is any difference between using fprintf with a variable or not? Other than the memory usage of x in this case.

fprintf(stderr,"%d", 1);

vs

int x = 1;

fprintf(stderr,"%d", x);
3
  • The memory usage is the same. The compiler translates the code beforehand to be better. You don't ever have to manually optimize. Commented Oct 13, 2015 at 17:15
  • @brunch875 not necessarily... Optimization is not required to be implemented. Commented Oct 13, 2015 at 17:16
  • Expressions are always evaluated, and both 1 and x are evaluated to the same. Commented Oct 13, 2015 at 17:31

1 Answer 1

3

There's no difference. Both x and 1 are of type int, so there is no difference between the two as far as printf is concerned.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, in both cases an int value is supplied as an argument and printf() won't know whether it was from a variable or an immediate value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.