About Lesson
Character:
In C, the char data type is used to represent individual characters. It is one of the primary data types and is commonly used for variables that store single characters. The char type typically occupies 1 byte in memory.
Example:
#include <stdio.h>
int main() {
// Declaration and initialization of char variables
char letter1 = ‘A’;
char letter2 = ‘b’;// Displaying the values
printf(“Letter 1: %cn”, letter1);
printf(“Letter 2: %cn”, letter2);return 0;
}
Output:
Letter 1: A
Letter 2: b
Explanation of code:
- #include <stdio.h>: This line includes the standard input-output library for functions like printf.
- int main(): The main function, where the program execution begins.
- char letter1 = ‘A’; and char letter2 = ‘b’;: Declaration and initialization of char variables.
- printf(“Letter 1: %cn”, letter1);: Printing the value of letter1 using the %c format specifier.
- Similarly, the value of letter2 is printed using printf.
- return 0;: Indicates successful program execution.