Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
main()
{
char x;
int y;
x=100;
y=125;
printf("%c\n",x);
printf("%c\n",y);
printf("%d\n",x);
}

plzz give me proper explanation for the Output.

What I have tried:

on running this code i am getting output as
d
}
100



but why????????
Posted
Updated 3-Jan-18 8:43am
Comments
ZurdoDev 3-Jan-18 11:15am    
Which line of output do you have a question about? The third one should be real obvious.
CHill60 4-Jan-18 9:05am    
By the way, people will treat you and your questions more seriously if you stop using text-speak (it's "please" not "plzz"). Not everyone has English as a first language and your use of slang is alienating you from potential help.

Because that's what you asked for.
See here: ASCII table[^]

The "%c" specifier says "treat the input value as a character and print that". Look at the table, and find "100" under the "Dec" column - it's a lower case "d". Now look for "125" in the same column and it's "}".
So you asked it to print your value as a character, and that is exactly what it did.
 
Share this answer
 
You have, when looked at along with your previous question, a very great need to study the C data types. C, perhaps more than any other language you're likely to use, will let you do foolish things because you asked it to do them.

C was written, originally, to write operating systems. That means it is allowed to do pretty much anything you ask it to do - including mixing up types. It will, depending upon your compiler, let these go without any errors or warnings. Most of the time is flags problems for you, but some things are reasonably requests . . . even if they're not at all what you wanted to do.

I have deliberately, for example, taken a string of characters and interpreted them as integers.

SO PLEASE study C data types.
 
Share this answer
 
v2
Comments
Amit Razdan 4-Jan-18 9:45am    
thank u sir....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900