C Language

Character or Char

In C Language by Baqir AliLeave a Comment

Character in C

The type char represents single characters. A character is enclosed in single quotes such as ‘a’, ‘b’. Characters are declared using the statement

#include <stdio.h>
void main(void)
{
   char a;
   a='T';
   printf("Value of a is %c",a);
}

in the above example a is a character variable or identifier and ‘T’ is the character constant or value of variable a;

Output is:

Value of a is T

Character Types in C On a 16-bit System

Type Approximate Range
char (signed) -128..127
unsigned char 0..255

char – special characters

Character Name Meaning
\b Backspace Move the cursor to the left by one character
\n New line Go to next line
\r Return Go to beginning of current Line
\t Tab Advance to next tab stop
\’ Apostrophe Character ‘
\” Double quote Character “
\\ Backslash Character \

We can also use char data type to print ASCII table characters on the screen

ASCII in c
ASCII in c

Example

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int i;
	for(i=65; i<91; i++)
	{
		printf("%c ",i);
		
	}
	printf("\n");
	for(i=90;i>=65;i--)
	{
		printf("%c ",i);
	}
	printf("\n");
	for(i=97;i<=122;i++)
	{
		printf("%c ",i);
	}
	printf("\n");
	for(i=122;i>=97;i--)
	{
		printf("%c ",i);
	}
	return 0;
}
Characters in C
Characters in C

Character in C Coding

Support us by sharing this post

About the Author

Baqir Ali

Facebook Twitter

Hi, I am Baqir Ali ---- Blogger, Programmer, and a Teacher. I am currently working as a Programmer for Softnat Technologies. I have tons of ideas and data to share with you all via blogging.

Leave a Comment