ASCII Values In C

C programming language uses ASCII codes to represent characters. ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns unique numeric codes to each character. In this article, we will discuss ASCII values in C programming language, their usage, and examples.

An ASCII value is a unique numeric code assigned to each character in the ASCII character set


(toc)


ASCII Values in C

ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns a unique numerical code to each character, including letters, numbers, punctuation marks, and control characters. In C, characters are represented internally as integers, and their ASCII values can be accessed and manipulated.  


Accessing ASCII Values

To access the ASCII value of a character in C, you can simply treat the character as an integer. This is because characters are stored as integers under the hood.


Example:


char ch = 'A';
int ascii_value = ch;
printf("ASCII value of 'A' is: %d\n", ascii_value);

Output:

ASCII value of 'A' is: 65

Converting ASCII Values to Characters


You can convert an ASCII value back to its corresponding character using type casting:


int ascii_value = 65;
char ch = (char)ascii_value;
printf("Character corresponding to ASCII value 65 is: %c\n", ch);

Output:

Character corresponding to ASCII value 65 is: A

ASCII Table

The ASCII table lists the characters and their corresponding numerical values. You can find a complete ASCII table online.


Common ASCII Values:

  • 'A' to 'Z': 65 to 90
  • 'a' to 'z': 97 to 122
  • '0' to '9': 48 to 57
  • '\n': 10 (newline)
  • '\t': 9 (tab)

Using ASCII Values

ASCII values can be used for various purposes, such as:

  • Character conversion: Converting between uppercase and lowercase letters.
  • String manipulation: Implementing string functions like strlen, strcmp, and strcpy.
  • Character encoding and decoding.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!