Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Character

The char Type

The char data type is employed for storing individual characters.

Characters must be enclosed in single quotes, such as ‘A’ or ‘c’, and we utilize the %c format specifier to print them.

Example

char myGrade = ‘A’;
printf(“%c”, myGrade); 

Alternatively, if you’re acquainted with ASCII, you can utilize ASCII values to represent specific characters.

Note that these values are numerical and are not enclosed in quotes ( ).

Example

char a = 65, b = 66, c = 67;
printf(“%c”, a);
printf(“%c”, b);
printf(“%c”, c); 

Tip: You can refer to our ASCII Table Reference for a comprehensive list of all ASCII values.

Notes on Characters

Attempting to store more than a single character will result in only the last character being printed.

Example

char myText = ‘Hello’;
printf(“%c”, myText); 

 

Note: Avoid using the char type for storing multiple characters to prevent potential errors.

For storing multiple characters or entire words, employ strings, which will be covered in detail in a subsequent chapter.

Example

char myText[] = “Hello”;
printf(“%s”, myText); 

 

For now, understand that we utilize strings for storing multiple characters or text, while the char type is used for single characters.