C Program To Print ASCII Value of a Character
Given a character, we need to print its ASCII value in C.
Examples:
Input: a Output: 97 Input: D Output: 68
C code: We use format specifier here to give numeric value of character. Here %d is used to convert character to its ASCII value.
C
// C program to print // ASCII Value of Character #include <stdio.h> // Driver code int main() { char c = 'k' ; // %d displays the integer value of // a character // %c displays the actual character printf ( "The ASCII value of %c is %d" , c, c); return 0; } |
Output:
The ASCII value of k is 107
Time complexity: O(1) since performing constant operations
Auxiliary Space: O(1)
Please refer complete article on Program to print ASCII Value of a character for more details!