# Programming Tutorials

## The C Character Set

By: Nithya Suresh Printer Friendly Format

A character denotes any alphabet ,digit or symbols to represent information.The following are the valid alphabets, numbers and special symbols permitted in C

Numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Alphabets: a, b, ….z

A, B, ……...Z

Arithmetic Operations: +, -, *, /, %(Mod)

Special Characters:

 ( ) { } [ ] < > = ! \$ ? . , : ; ‘ “ & | ^ ~ ` # \ blank - _ / * % @

CONSTANTS, VARIABLES AND KEYWORDS

A ‘constant’ is an entity that does not change, but a ‘variable’ as the name suggests may change. We do  a number of calculations in a computer and the computed values are stored in some memory spaces. Inorder to retrieve and re-use those values from the computer’s memory locations they are given names. Since the value stored in each location may change, the names given to these locations are called as ‘variable names’.

Constants:

There are mainly three types of constants namely: integer, real and character constants.

Integer Constants:

The integer constants

• Whole Numbers
• Eg. 25, 35, -25, -46
• Computer allocates only 2 bytes in memory.
• 16th bit is sign bit. (if 0 then +ve value, if 1 then –ve value)

1       1       1       1        1       1       1      1       1        1       1        1       1       1        1

214        213       212         211        210        29         28      27      26        25          24           23         22           21           20

= 1*1  +  4*1  +  8*1  +  16*1  +  32*1  +  64*1  + 128*1  +  256*1  +  512*1  +  1024*1  +  2048*1  +  4096*1  +  2*1  +  8192*1  +  16284*1

=  32767 (32767 Bits can be stored for integer constants)

• 32768 is negative
• -32767 is minimum

(i) Decimal Integer Constant:

• 0 to 9
• E.g: 49, 58, -62, … (40000 cannot come bcoz it is > 32767)

(ii) Octal Integer Constant:

• 0 to 7
• Add “0” before the value.
• Eg.: 045, 056, 067

• 0 to 9 and A to F
• Add 0x before the value
• E.g: 0x42, 0x56, 0x67

REAL CONSTANTS:

The real or floating point constants are in two forms namely fractional form and the exponential form.

A real constant in fractional form must:

• Have at least one digit
• It must have a decimal point
• Could have positive or negative sign(default sign is positive)
• Must not have commas or spaces within it
• Allots 4 bytes in memory

Ex:  +867.9, -26.9876, 654.0

In exponential form, the real constant is represented as two parts. The part lying before the ‘e’ is the ‘mantissa’, and the one following ‘e’ is the ‘exponent’.

The real constant in exponential form must follow the following rules:

• The mantissa part and the exponential part should be separated by the letter ‘e’
• The mantissa may have a positive or negative sign(default sign is positive)
• The exponent must have at least one digit
• The exponent must be a positive or negative integer(default sign is positive)
• The range of real constants in exponential form is -3.4e38 and -3.4e38

Ex:  +3.2e-4,  4.1e8,  -0.2e+4,  -3.2e-4

CHARACTER CONSTANTS

A character constant is an alphabet, a single digit or a single special symbol enclosed within inverted commas. The maximum length of a character constant can be 1 character. Allots 1 byte of memory

Ex:  ’B’,  ’l’,    ’#’

Types of C Variables

Variable names are names given to locations in the memory. These locations can contain integer, real or character constants. An integer variable can hold only an integer constant, a real variable can hold only a real constant and a character variable can hold only a character constant.

Rules for Constructing Variable Names

A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters.

• The first character in the variable name must be an alphabet
• No commas or blanks are allowed within a variable name.
• No special symbol other than an underscore (as in net_sal) can be used in a variable name.

Ex.: si_int

e_hra

pod_e_81

C compiler makes it compulsory for the user to declare the type of any variable name that he wishes to use in a program. This type declaration is done at the beginning of the program. Following are the examples of type declaration statements:

Ex.: int si, e_hra ;

float bas_sal ;

char code ;

Since, the maximum allowable length of a variable name is 31 characters, an enormous number of variable names can be constructed using the above-mentioned rules. It is a good practice to exploit this enormous choice in naming variables by using meaningful variable names.

C Keywords

C makes use of only 32 keywords or reserved words which combine with the formal syntax to the form the C programming language. Note that all keywords in C are written in lower case. A keyword may not be used as a variable name.

 auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

 Most Viewed Articles (in C ) Latest Articles (in C)

Comment on this tutorial

#### Subscribe to Tutorials

1. Good
View Tutorial          By: sandesh at 2009-10-01 01:15:29

2. Excellent
View Tutorial          By: Jaleel at 2009-10-16 23:22:52

3. excellent..... thanks it help me a lot.......
View Tutorial          By: REJAPUTRA at 2009-10-23 09:19:25

4. very nice
View Tutorial          By: prasad at 2009-11-11 05:03:16

5. excellent to easy going
View Tutorial          By: murali at 2009-11-15 23:13:21

6. Tit for tat
View Tutorial          By: Sagar at 2010-03-23 13:06:17

7. keep it up!
View Tutorial          By: kamran at 2010-04-13 07:01:26

8. very nice thank you so much my dude
View Tutorial          By: mohd at 2010-07-28 02:40:23

9. good but you don't express the programs examples
View Tutorial          By: anchal at 2010-09-29 02:40:02

10. very good.......
View Tutorial          By: Waqas Gondal at 2010-10-28 03:51:21

11. thanx.thats a useful material for the students, in
View Tutorial          By: MUHAMMAD ABUBAKAR YASEEN at 2010-10-28 04:19:00

12. It is very useful.thank you so much.
View Tutorial          By: Pratiksha ijagaj at 2010-11-27 07:03:52

13. easy to understand and it helped me a lot in prepa
View Tutorial          By: shandini at 2011-04-14 13:14:33

14. excellent
View Tutorial          By: shamim at 2011-07-08 02:39:31

15. excellent...... thank you so much.
View Tutorial          By: balaji at 2011-07-19 07:56:08

16. Good....... and useful material for students
View Tutorial          By: Ratna at 2011-08-17 04:41:01

17. classic ... details
View Tutorial          By: vinod at 2011-09-09 10:45:25

18. thanks from <a href="http://www.careersoft
View Tutorial          By: tarun at 2012-04-28 15:40:16

19. super excellent
View Tutorial          By: mani at 2013-05-27 05:32:06

20. It is very useful ....Thank U sooo much dear...
View Tutorial          By: Augustine Francis at 2014-06-24 16:55:21