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.

Recommended Answers

All 4 Replies

I think it prints a value in a register.

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.

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)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.