Jump to content
ChetanaSforum
Sign in to follow this  
chitkaraankit

predict output c

Recommended Posts

int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }

Share this post


Link to post
Share on other sites

int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }

O/P: 302010in C programming the compiler will check for the values at the stack at last the const volatile unsigned i=03; was declared inside the parenthesis and hence compiler will choose the local variable for the first printf statement.consecutively for the rest of the statements it chooses the local parameters located in the stack for the output.hence at first it prints 30 then the second output will be 20 finally 10.output: 302010

Share this post


Link to post
Share on other sites

int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }

because The variable declare inside Block then its Scope is within that Blockwhether we declare it extern its Reintialization supress its previous deceleration and it act as new variableexcept static

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
Sign in to follow this  



×