The C Character Set
By: Nithya Suresh in C Tutorials on 2008-07-05
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
(iii) Hexadecimal Integer:
- 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 |
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Sum of the elements of an array in C
Printing a simple histogram in C
Find square and square root for a given number in C
Simple arithmetic calculations in C
Passing double value to a function in C
Passing pointer to a function in C
Infix to Prefix And Postfix in C
while, do while and for loops in C
Comments