Constants

The constants are the values which never changes. The C uses following types of constants.
Integer constants :
                Integer constants represent the whole numbers. They uses digits 0 to 9 and optional sign + or - before the number. The following are examples of valid integer constants.

123
-23
65535
0
+85

                The space, comma and other special symbols are not allowed. The following are examples of invalid integer constants.
10,000
 $500
15 780
Real Constant :
                Real Constants represent the numbers with fractional parts i.e digits after decimal point. They are used to represent contiguous quantities like temperature of day. The following are examples of valid real constants.
0.0005
-0.123
+248.0
215.
.78
 Character Constants :
Character constants represent single character and are always enclosed in single quotes. The following are examples of valid character constants.
'A'         'a'         '?'         ':'         '8'
                The characters are stored  in computer memory in form of their ASCII values. For example, ASCII value of 'A' is 65 and ASCII value of '8' is 56. Study the following program to find out ASCII values of particular characters.
#include <stdio.h>
void main()
{
 char c;
 printf(" Enter a Character: ");
 scanf("%c",&c);
 printf("ASCII of '%c' is %d\n",c,c);
}
Output: -
Enter a Character:a                                                                                                                                              
ASCII of 'a' is 97

Comments

Popular posts from this blog

Data Types in C Programming

Identifiers