In C, characters are represented using the char data type, which typically occupies one byte (8 bits) of memory. Each character corresponds to an integer value based on the ASCII encoding or other character encoding schemes.
Here's a brief overview:
- ASCII: The first 128 characters (0-127) are represented using ASCII values. For example, the character 'A' is represented by the integer value 65.
- Extended ASCII: Values from 128 to 255 can represent additional characters, depending on the specific encoding used (e.g., ISO-8859-1).
- Unicode: For broader character representation, C can use libraries that support Unicode, allowing for a wide range of characters from different languages.
You can declare a character variable in C like this:
char letter = 'A';
To print a character, you can use the printf function:
#include <stdio.h>
int main() {
char letter = 'A';
printf("The character is: %c\n", letter);
return 0;
}
This will output:
The character is: A
