Computer Science And Engineering At the end up in a new life and I have faced by phone call and I am not your own message of love for each and everyone!
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
50 views7 pages
Char Data Type: Single Quote '
Computer Science And Engineering At the end up in a new life and I have faced by phone call and I am not your own message of love for each and everyone!
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7
Char data type
▪ Characters (char) – To store a character into a char
variable,you must enclose it with SINGLE QUOTE marks i.e. by ‘ ’. ▪ The double quotes are reserved for string(a collection of character). ▪ The character that you assign are called as character constants. ▪ You can assign a char variable an integer, i.e., its integer value. ‘a’, ‘z’ , ‘A’ , ‘Z’ , ‘?’, ‘@’, ‘0’, ‘9’ - Special Characters: preceded by \ ‘\n’, ‘\t’ , ‘\0’, ‘\’’, ‘\\’ etc. Initialization
▪ Initializing a variable involves assigning(putting in) a value for
the first time. This is done by using the ASSIGNMENT OPERATOR, denoted by the equals sign,=.
▪ Declaration and initializing can be done on separate lines, or
on one line.
▪ char c=‘x’; or char c; c=‘x’ Printing value of char variable
printf( “%c”, a);
This causes the “ %c” to be replaced by value of
character variable a.
printf(“\n %c”, a);
“\n” is a new line character which will print the value of
variable on newline. Variables and Constants
▪ Variables are like containers in your computer’s
memory-you can store values in them and retrieve or modify them when necessary
▪ Constants are like variables,but once a value is stored,its
value can not be changed. Naming Variables Expressions
▪ Expressions consist of a mixture of constants,variables and
operators .They return values. ▪ Examples are: – 17 -X*B/C+A – X+17 Program using character constants #include<stdio.h> int main() { char a,b,c,d; /* declare char variables*/ char e='o'; /* declare char variable*/ a='H'; /* initialize the rest */ b='e'; /* b=e is incorrect */ c='l'; /* c=“l” is incorrect*/ d=108; /* the ASCII value of l is 108 */ printf("%c%c%c%c%c",a,b,c,d,e); return 0; }