0

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.

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Tom Gunn
0

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.

0

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)

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.