944,089 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 416
  • C RSS
Nov 10th, 2009
0

printf with no args - behaviour

Expand Post »
can somebody explain the behaviour of the statement

printf("%d");

is it any where depends on the statements that present before or after it.

i have some satatements that allocates memory dynamically. its printing one of that value.

is there any proper reason for undefined behaviour.
Similar Threads
Reputation Points: 34
Solved Threads: 4
Junior Poster
Iam3R is offline Offline
110 posts
since Oct 2009
Nov 10th, 2009
0
Re: printf with no args - behaviour
I think it prints a value in a register.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
wingless is offline Offline
15 posts
since Oct 2009
Nov 10th, 2009
0
Re: printf with no args - behaviour
Quote ...
can somebody explain the behaviour of the statement

printf("%d");
Undefined. In practice it will probably print whatever is next in the stack and potentially corrupt the rest of your program by moving the stack pointer in an unexpected way.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Nov 11th, 2009
0
Re: printf with no args - behaviour
Click to Expand / Collapse  Quote originally posted by Tom Gunn ...
Undefined. In practice it will probably print whatever is next in the stack and potentially corrupt the rest of your program by moving the stack pointer in an unexpected way.

so suppose if we rememeber the previous values of the stack can we expect the same values as out put.
( i believe we should not do this way , but any way the system it self is giving same results every time when i run the program)
Reputation Points: 34
Solved Threads: 4
Junior Poster
Iam3R is offline Offline
110 posts
since Oct 2009
Nov 11th, 2009
0
Re: printf with no args - behaviour
Quote ...
so suppose if we rememeber the previous values of the stack can we expect the same values as out put.
No. That is the nature of undefined behavior, it is unpredictable. We can only speculate about what will happen and hope that it happens consistently.
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: help me
Next Thread in C Forum Timeline: urgent help needed in c





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC