In this tutorial you will learn about Character Set, C Character-Set Table, Special Characters, White Space, Keywords and Identifiers, Constants, Integer Constants, Decimal Integers, Octal Integers, Hexadecimal integer, Real Constants, Single Character Constants, String Constants, Backslash Character Constants [Escape Sequences] and Variables. The character set in C Language can be grouped into the following categories. 1. Letters White Spaces are ignored by the compiler until they are a part of string constant. White Space may be used to separate words, but are strictly prohibited while using between characters of keywords or identifiers. Letters Digits Upper Case A to Z 0 to 9 Lower Case a to z Special Characters , .Comma & .Ampersand . .Period ^ ; .Semicolon * .Asterisk : .Colon - .Minus Sign ? .Question Mark + .Plus Sign ' .Aphostrophe < .Opening Angle (Less than sign) " .Quotation Marks > .Closing Angle (Greater than sign) ! .Exclaimation Mark ( .Left Parenthesis | .Vertical Bar ) .Right Parenthesis / .Slash [ .Left Bracket \ .Backslash ] .Right Bracket ~ .Tilde { .Left Brace - .Underscore } .Right Bracket $ .Dollar Sign # .Number Sign % 1. Blank Space The following are the Keyword set of C language. some compilers may have additional keywords listed in C manual. Identifiers refers to the name of user-defined variables, array and functions. A variable should be essentially a sequence of letters and or digits and the variable name should begin with a character. Both uppercase and lowercase letters are permitted. The underscore character is also permitted in identifiers.C Programming Language - Constants and Variables
Character Set
2. Digits
3. Special Characters
4. White SpacesC Character-Set Table
.
.Caret .Percentage Sign . . .
.
.
White Space
2. Horizontal Tab
3. Carriage Return
4. New Line
5. Form FeedKeywords and Identifiers
.auto .else .register .union .break .enum .return .unsigned .case .extern .short .void .char .float .signed .volatile .const .for .size of .while .continue .goto .static . .default .if .struct . .do .int .switch . .double .long .typedef .
1. First character must be an alphabet (or underscore)
2. Identifier names must consists of only letters, digits and underscore.
3. A identifier name should have less than 31 characters.
4. Any standard C language keyword cannot be used as a variable name.
5. A identifier should not contain a space.
Constants
A constant value is the one which does not change during the execution of a program. C supports several types of constants.
1. Integer Constants
2. Real Constants
3. Single Character Constants
4. String Constants
Integer Constants
An integer constant is a sequence of digits. There are 3 types of integers namely decimal integer, octal integers and hexadecimal integer.
Decimal Integers consists of a set of digits 0 to 9 preceded by an optional + or - sign. Spaces, commas and non digit characters are not permitted between digits. Example for valid decimal integer constants are
123
-31
0
562321
+ 78
Some examples for invalid integer constants are
15 750
20,000
Rs. 1000
Octal Integers constant consists of any combination of digits from 0 through 7 with a O at the beginning. Some examples of octal integers are
O26
O
O347
O676
Hexadecimal integer constant is preceded by OX or Ox, they may contain alphabets from A to F or a to f. The alphabets A to F refers to 10 to 15 in decimal digits. Example of valid hexadecimal integers are
OX2
OX8C
OXbcd
Ox
Real Constants consists of a fractional part in their representation. Integer constants are inadequate to represent quantities that vary continuously. These quantities are represented by numbers containing fractional parts like 26.082. Example of real constants are
0.0026
-0.97
435.29
+487.0
Real Numbers can also be represented by exponential notation. The general form for exponential notation is mantissa exponent. The mantissa is either a real number expressed in decimal notation or an integer. The exponent is an integer number with an optional plus or minus sign.
A Single Character constant represent a single character which is enclosed in a pair of quotation symbols. Example for character constants are '5' All character constants have an equivalent integer value which are called ASCII Values. A string constant is a set of characters enclosed in double quotation marks. The characters in a string constant sequence may be a alphabet, number, special character and blank space. Example of string constants are "VISHAL" Backslash character constants are special characters used in output functions. Although they contain two characters they represent only one character. Given below is the table of escape sequence and their meanings. Constant Meaning '\a' '\b' .Backspace '\f' '\n' '\r' '\t' '\v' '\'' '\"' '\?' '\\' '\0' A variable is a value that can change any time. It is a memory location used to store a data value. A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program. Variable names are case sensitive. Example of variable names are Sun Any variable declared in a program should confirm to the following 1. They must always begin with a letter, although some systems permit underscore as the first character. Examples of Invalid Variable names are 123
'x'
';'
' 'String Constants
"1234"
"God Bless"
"!.....?"Backslash Character Constants [Escape Sequences]
.Audible Alert (Bell) .Formfeed .New Line .Carriage Return .Horizontal tab .Vertical Tab .Single Quote .Double Quote .Question Mark .Back Slash .Null
Variables
number
Salary
Emp_name
average1
2. The length of a variable must not be more than 8 characters.
3. White space is not allowed and
4. A variable should not be a Keyword
5. It should not contain any special characters.
(area)
6th
%abc

No comments:
Post a Comment