This question is releated to C Langauge
What is the answer of the following and how it is comming:-
#include
#include
main()
{
char a='\101';
printf("%c",a);
}
Web Development
What is the answer of the following and how it is comming:-
#include
#include
main()
{
char a='\101';
printf("%c",a);
}
by epepke
That should print a capital A to standard output. \101 means octal 101 which means hexadecimal 41 which maps to capital A in ASCII. The %c code in printf prints a single character.
Note that %c only works safely with single-byte characters, i.e. ASCII. It isn't safe to use on a multi-byte character set such as Unicode.
by ms_saini3302
by ms_saini3302
by emcs
I copied:
#include
#include
main()
{
char a='\101';
printf("%c",a);
}
from your question.
The answer is A.
102 = B
103 = C
104 = D
105 = E
106 = F
107 = G
110 = H
111 = I
etc
117 = O
120 = P
As was stated in #1, the \ in '\101' indicates octal. '\100' = @.
This program is taking any the number, and giving the user friendly key notation. Remember that octal's do not always give A-Z, a-z, 0-9, one of the other symbols like@, ^, &. It may return the LF, VT, or any the remainding commands.
What else are you looking for in this program? It really is doing what you have asked it to do.
Let me know if this helps or hurs.
dennie
by emcs
As you can see in the above: helps or hurs. Spelling doesnot count.
I did see where you asked this a couple of time. I again ask as someone else said, what do you think is wrong, or where you just not clear with what the output should be?
Let us know what is confusing you, someone can help.
dennie
by ms_saini3302
by epepke
It's taking an octal value because that's the way the language is defined. Backslash followed by three digits in a quoted character or string MEANS take the octal value.
The question "why" is almost meaningless. It works that way because, a quarter of a century ago, the designers of the language decided that's what it should mean. Perhaps they were used to specifying characters in octal, and they wanted to do that in their new language. It's just like the fact that preceding an integer with a 0 outside of a string means use octal. So, a=0101 would set a to octal 101, which is decimal 65.
Why? Because that's how they defined it. It's arbitrary, but that's the way it is. They could have chosen to make it decimal, but they didn't, and we just have to live with the fact.
by ms_saini3302
by ms_saini3302
This discussion is closed to new replies.
Sort by Trending