Thursday, 7 November 2013

C LANGUAGE COMPONENTS

C Language Components

The four main components of C language are

1) The Character Set.
2) Tokens
3) Variables
4) Data Types
1) The Character Set : Character set is a set of valid characters that a language cab recognize. A character represents any letter, digit or any other sign.
 Letters - A,B,C……Z or a,b,c …………z.
 Digits - 0,1…………9
 Special Symbols - ~!@#$%^&.........
 White Spaces - Blank space, horizontal tab, carriage return,
new line, form feed.
2) Tokens: The smallest individual unit in a program is known as a token.
C has five tokens
i. Keywords
ii. Identifiers
iii. Constants
iv. Punctuations
v. Operators

i. Keywords: Keywords are reserved word in C. They have predefined meaning cannot changed. All keywords must be written in lowercase. Eg:- auto,long,char,short etc.
ii. Identifiers: - Identifiers refer to the names of variable, functions and arrays. These are user-defined names. An identifier in C can be made up of letters, digits and underscore. Identifiers may start with either alphabets or underscore. The underscore is used to make the identifiers easy to read and mark functions or library members.
iii. Constants: - Constants in C refers to fixed values that do not change during the execution of a program. C support several types of constants.
a. Numerical Constants
i. Integer Constant
1. Decimal Constant
2. Octal Constant
3. Hexadecimal Constant
ii. Float Constant
b. Character Constants
i. Single Character Constant
ii. String Constant
Integer Constant: - An integer constant is a whole number without any fractional part. C has three types of integer constants.
Decimal Constant: - Decimal integers consists of digits from 0 through 9
Eg.: 34,900,3457,-978
Octal Constant: - An Octal integer constant can be any combination of digits from 0 through 7. In C the first digit of an octal number must be a zero(0) so as to differentiate it from a decimal number. Eg.: 06,034,-07564
Hexadecimal Constant: Hexadecimal integer constants can be any combination of digits 0 through 9 and alphabets from „a‟ through „f‟ or „A‟ through „F‟. In C, a hexadecimal constant must begin with 0x or 0X (zero x) so as to differentiate it from a decimal number. Eg:- 0x50,0XAC2 etc
Floating Constants (Real): Real or floating point numbers can contain both an integer part and a fractional part in the number. Floating point numbers may be represented in two forms, either in the fractional form or in the exponent form.
A float point number in fractional form consists of signed or unsigned digits including decimal point between digits. E.g:- 18.5, .18 etc.
Very large and very small numbers are represented using the exponent form. The exponent notation use the „E‟ or „e‟ symbol in the representation of the number. The number before the „E‟ is called as mantissa and the number after forms the exponent
Eg.:-5.3E-5,-6.79E3,78e05

Single Character Constant: - A character constant in usually a single character or any symbol enclosed by apostrophes or single quotes. Eg.: ch=‟a‟

String Constant: - A sequence of character enclosed between double quotes is called string constant. Eg.: “Hello Good Morning”
iv) Punctuations: - 23 characters are used as punctuations in C. eg: + _ / ; : > ! etc
v) Operators: - An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation on data stored in variables. The variables that are operated as operands. C operator can be classified into 8 types.
i. Arithmetic Operators : + - * / %
ii. Assignment Operators : =
iii. Relational Operators: < > <= >= == !=
iv. Logical Operators:! && ||
v. Conditional Operators: ! :
vi. Increment & Decrement Operator : ++ --
vii. Bitwise Operator:! & | ~ ^ << >>
viii. Special Operator : sizeof ,(comma)

3) Variables: A variable is an object or element that may take on any value or a specified type. Variable are nothing but identifiers, which are used to identify variables programming elements. Eg: name, sum, stu_name, acc_no etc.
4) Data types: Data types indicate the types of data a variable can have. A data types usually define a set of values, which can be stored in the variable along with the operations that may be performed on those values. C includes two types of data.
 Simple or Fundamental data type
 Derived data type
Simple Data Types: There are four simple data types in C.
 int
 char
 float
 double
int:- This means that the variable is an integer are stored in 2 bytes, may range from -32768 to 32767.
char:- This means that the variable is a character type, char objects are stored in one byte. If unsigned, the values may be in the range 0 to 255.
Float:- This means that the variable is a real number stored in 4 bytes or 32 bits. The range of floating point values are between 3.4E-38 to 3.4E38 or 6 significant digits after the decimal point.
Double: This means that the variable is a double precision float type. In most cases the systems allocates 8 bytes or 64 bits space, between 1.7E-308 to 1.7E308.
Derived Data Types: Derived data types are constructed from the simple data types and or other derived data types. Derived data include arrays, functions, pointers, references, constants, structures
unions and enumerations.

No comments:

Post a Comment