printf with no args - behaviour

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 50
Reputation: Iam3R is an unknown quantity at this point 
Solved Threads: 3
Iam3R Iam3R is offline Offline
Junior Poster in Training

printf with no args - behaviour

 
0
  #1
24 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: wingless is an unknown quantity at this point 
Solved Threads: 0
wingless wingless is offline Offline
Newbie Poster
 
0
  #2
24 Days Ago
I think it prints a value in a register.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 133
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster
 
0
  #3
24 Days Ago
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.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 50
Reputation: Iam3R is an unknown quantity at this point 
Solved Threads: 3
Iam3R Iam3R is offline Offline
Junior Poster in Training
 
0
  #4
23 Days Ago
Originally Posted by Tom Gunn View Post
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)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 133
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster
 
0
  #5
23 Days Ago
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.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC