Jump to content
ChetanaSforum
Sign in to follow this  
chitkaraankit

predict output

Recommended Posts

Predict the output of the following code.main(){int i=012;int j=034;int k=056;printf("i = %d\n",i);printf("j = %d\n",j);printf("k = %d\n",k);}

Share this post


Link to post
Share on other sites

10

28

46

 

In C, any number that begins with zero(0) is an octal number, and hence the numbers assigned to i,j and k are octal numbers. An octal number in the C programming language can contain only numbers from 0 to 7 and so, if you include any other number other than the ones allowed, you're likely to get an error.

 

When printing them using %d, they're converted to the decimal format. If you wanna print the numbers as is, you'd have to replace %d by %o. Posted Image

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  



×