(1) #include
int main()
{
char a = '\012';
printf("%d", a);
return 0;
}
The output is 10.
char a = '\012'; ==> Stores octal value of 12 to a , which is 001010.
printf("%d", a); ==> Printing it in decimal will print 10.
(2) #include
int main()
{
char a = '012';
printf("%d", a);
return 0;
}
The output is 50.
char a = '012'; ==> Here ASCII values of each character get stored (to the same location). 0 has ASCII value 48, then 1 with 49, finally 50 is stored for character 2. Now printing it in decimal gives 50 as output.
3. #include
int main()
{
char a = '\012';
printf("%c", a);
return 0;
}
The output is Linefeed Character (or New Line)
char a = '\012'; ==> This is same as the first case where octal value for 12 (00001010) is stored in a. This has a decimal value 10, and the corresponding ASCII character is 'Line Feed'.
printf("%c", a); ==> Prints character value
So the output will go to New Line on printing 10 as a character.