Notes_Features_C Tokens and Data Types
Notes_Features_C Tokens and Data Types
History of C
C was developed by a system programmer Dennis Ritchie in 1972, at American Telegraph
& Telecommunication (AT & T) Bell Laboratories in New Jersey USA. The C language is
often referred as middle level language because we can write high level as well as low
level programs through C.
Features of C
• C is a general purpose programming language. You can generate games, business
software, utilities, mathematical models, word processors, spreadsheets and other
kinds of software.
• C is a structured programming language. It uses structured statements such as
while, for loops in place of goto statement which cause bugs (error) in the program.
• System programming: C is used for system programming i.e. writing operating
system. The UNIX operating system is also rewritten from C. Major parts of
Windows, Linux, UNIX are still written in C because speed of execution is very fast
in C compare to other languages.
Structure of C program:
Documentation Section
Link Section (#include section)
Definition Section
Global Declaration Section
Main Function Section
{
Declaration Part
Execution Part
}
Subprogram Section (User Defined Function)
Function 1
Function 2
….
Function n
Preprocessor
A preprocessor is a program that processes our program before it is passed to the
compiler. Preprocessing is the first step of the language processing system. A
preprocessor mainly performs three tasks on the High Level Language code:
1. Removing comments
2. File inclusion
3. Macro expansion
C Tokens
Tokens are the smallest individual unit of a program. Each and every punctuation and
word that you come across in a C program is token. C programs are written using these
tokens and the syntax of the language. C has six types of tokens:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special symbols
6. Operators
Identifiers
Identifiers are the names given to variables, arrays, functions, pointers and structures.
These are user-defined names and consist of a sequence of letters and digits, with a letter
as a first character. Both uppercase and lowercase letters are permitted.
Variables
A variable is the name of a memory location that we use for storing data. We can change
the value of a variable and we can also reuse it multiple times. Each variable has a name,
data-type, size and the value it stores.
Rules for constructing variable name in C language are listed below:
• Variable name may be a combination of alphabets, digits or underscores.
• First character must be an alphabet or underscore.
• No commas or blank spaces are allowed in a variable name.
• No word, having a reserved meaning in C can be used for variable name.
• Lower and upper case letters are significant.
Constants
A constant in C refer to fixed values that does not change during the execution of a
program. There are four basic types of constants in C:
Character Constant
String Constant
Integer Constant
Real Constant
Integer Constant: An integer constant refers to a sequence of digits and has a numeric
value. There are three types of integers in C: decimal, octal and hexadecimal.
Decimal integers : 2, 45, -4 etc.
Octal integers : 020, -04 etc.
Hexadecimal integers : 0x4, -0x2B etc.
Real Constants: A number with a decimal point (fractional part) and an optional
preceding sign represents a real constant. A floating point number can also be
represented as exponential or scientific notation. For e.g. 0.0000987 can be written as
9.87*10-5 or 9.87e-05. Thus the general form is:
mantissa e exponent
So 9.87 is called mantissa and -05 is called as exponent.
Data Types
The way a value stored in a variable interpreted is known as its data type. In other words,
data type determines the type and size of data associated with variables. Every computer
language has its own set of data types it supports. A data type signifies two important
aspects:
1. Amount of space (size) to be reserved in the memory to store the data and
2. Nature (type) of data to be stored.
Data Types
Primitive/Primary/Basic Data Types Derived Data Types User Defined Data Types
- int - array - structure
- char - pointers - union
- float - typedef
- double - enum
- void
Sometimes the program requires only positive values. In such cases the data type can be
made unsigned. Thus the range of unsigned short int become 0 to 65535. Format specifier
for unsigned is %u. (unsigned short - %hu).
void type
The void type has no values. This is usually used to specify the type of functions. It can
also play the role of a generic type, meaning that it can represent any of the other
standard types.
typedef
C supports a feature known as ‘type definition’ that allows users to define an identifier that
would represent an existing data type. The user-defined data type identifier can later be
used to declare variables. It takes the general form:
typedef type identifier;
where type refers to an existing data type and ‘identifier’ refers to the ‘new’ name given to
the data type.