in Programming in C
322 views
0 votes
0 votes

Why nothing is printed for %c.

in Programming in C
322 views

1 Answer

2 votes
2 votes

In the code you provided, the printf statements that are intended to print the values of ‘a’, ‘b’, and ‘c’ as characters (%c) are not actually printing anything. This is because the values of ‘a’, ‘b’, and ‘c’ are not within the range of ASCII characters (0 to 127).

The %c format specifier is used to print a single character, and the character to be printed is specified as an integer value. The integer value is interpreted as an ASCII value, and the corresponding ASCII character is printed.

For example, if you want to print the character 'A', you can use the following printf statement:

printf("%c", 65);

This will print the character 'A' because the ASCII value for 'A' is 65.

However, if you try to print a value that is not within the range of ASCII characters, no character will be printed. For example:

printf("%c", 128);

This will not print anything because the ASCII value 128 is outside the range of ASCII characters (0 to 127).


 

EDIT: It might print the character 'Ç' on some systems. My system printed it though.

This is because ASCII values 128 to 255 are used to represent certain international and special characters on some systems, including the character 'Ç'. These characters are known as extended ASCII characters. 

But this code will definitely not print anything:-

   printf("%c", 256);

 

2 Comments

@Abhrajyoti00 In C language an integer value greater than 255 will be mod with 256 when assigned to a char. So, 256 is same as 0. And not all ASCII characters are “printable” – that’s why some don’t output anything. 0 for example is the NULL character.

2
2
Thanks for the rectification Sir. I thought that they are not printable because of out-of-range values
1
1

Related questions