Jump to content
ChetanaSforum
iamnemani

Not so obvious C Ques: printf('%d');

Recommended Posts

Hi,

Here is a C question whose answer is NOT so obvious. Let me know if you can figure it out:

Q. What is the output of printf("%d")?

Thank you,

~ nems

Share this post


Link to post
Share on other sites

Q. What is the output of printf("%d")?

hi sree, in c whenever u try to print some constant char type [ may be int , char , double ,... as per

printf( const char *s , ...) in stdio.h ] without using its data , it is the rule defined by the c compiler to provide a

garbage value derived from stack segment to show it as the data to it during compile time. so it not an error but the result is entirely depentdent upon the memory management layout of the corresponding compilers. so the garbage value may be of different pattern & even it is of different length also . here we use %d , so it is an integer, for char - it is a ascii null[ NUL ] char .

typically in ansi c / vc++ - it will show a unsigned 8-bit integer .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×