ASCII value in C

Here’s a C program that finds the ASCII value of a character

				
					#include <stdio.h>

int main() {
  char character;

  printf("Enter a character: ");
  scanf("%c", & character);

  printf("The ASCII value of '%c' is %d.\n", character, character);

  return 0;
}
				
			
Output
Printing ASCII Value of a Character in C
  • In this program, we declare a character variable of type char to store the input character from the user.

  • The user is prompted to enter a character using the printf function, and the scanf function is used to read the input and store it in the character variable.

  • To find the ASCII value of the character, we simply pass the character variable to printf using the %c format specifier to display the character itself, and %d format specifier to display its corresponding ASCII value.

  • Finally, the program displays the ASCII value of the entered character using printf.