0% found this document useful (0 votes)
3 views

Notes_Features_C Tokens and Data Types

The document provides an overview of the C programming language, detailing its history, features, structure, and essential components such as tokens, keywords, identifiers, variables, constants, and data types. It explains the significance of C as a middle-level language used for system programming and outlines the basic syntax and rules for constructing programs in C. Additionally, it describes the various data types available in C and their characteristics.

Uploaded by

suraj9873219771
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Notes_Features_C Tokens and Data Types

The document provides an overview of the C programming language, detailing its history, features, structure, and essential components such as tokens, keywords, identifiers, variables, constants, and data types. It explains the significance of C as a middle-level language used for system programming and outlines the basic syntax and rules for constructing programs in C. Additionally, it describes the various data types available in C and their characteristics.

Uploaded by

suraj9873219771
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PCE Programming for Problem Solving 1FY3-06

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’ Character Set


Character set of a language is set of all the symbols used to write a program in that
language. The characters in C are grouped into four categories:
1. Letters : A-Z or a-z
2. Digits : 0-9
3. Special symbols : ~, ‘! @#%^&*()_-+=\|{}[]:;” .?/
4. White spaces : blank space, tab space, carriage return, new-line, form-feed

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 1


PCE Programming for Problem Solving 1FY3-06

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

Keywords or Reserved Words


Keywords are predefined, reserved words used in programming that have special
meanings to the compiler. All keywords have fixed meanings and these meanings cannot
be changed. Keywords serve as basic building blocks for program statements. All
keywords must be written in lowercase. A list of keywords employed in C language:
auto double int struct break else long switch
case enum register typedef char extern return union
const float short unsigned continue for signed void
default goto sizeof volatile do if static while

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.

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 2


PCE Programming for Problem Solving 1FY3-06

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

Character Constants: A character constant consist of a single character, single digit or


a single special symbol enclosed within a pair of single inverted commas. All escape
sequences are also considered as character constant.
Example:
const char ch = ‘a’;

Backslash Character Constant (Escape Sequence): Certain non-printable characters,


which are used in the printf function are called as escape sequences. They always begin
with backslash (\).

Escape sequence Meaning


\n new line
\t Horizontal tab
\b Back space
\r Carriage return
\a bell alert
\” to print double quotation
\0 null (point end of the string)

String Constants: A string constant is a sequence of one or more characters enclosed


within a pair of double quotes (“ ”). If a single character is enclosed within a pair of double
quotes, it will also be interpreted as a string constant and not a character constant.
Example:
“Bhagirath Chauhan”

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.

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 3


PCE Programming for Problem Solving 1FY3-06

Difference between Variable and Constant

S.No. Variables Constants


Stores data type value in a It is similar to a variable but cannot be
1
program. changed during program execution.
It is a fixed variable that cannot be
It can be changed after defining the
2 changed after defining the variable in
variable in a program.
a program.

Typically, it uses int, float, char, It can be express in two ways:


3 double, etc. data types in a #define preprocessor and the const
program. keyword.
Example: cons tint size = 10; #define
4 Example: int a = 5; float pi = 3.14;
PI 3.14

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 4


PCE Programming for Problem Solving 1FY3-06

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

There are five primary data types in C language:

int data type


Integers are whole numbers with a range of values supported by a particular machine.
The range of an int data type is compiler dependent (2 or 4 bytes). The highest bit (MSB)
of an integer is used to store the sign of the integer. Format specifier for int data type is
%d.
In order to provide some control over the range of numbers and storage space, C has
three classes of integer storage, namely short int, int, and long int, in both signed and
unsigned forms.

short and long (modifiers)


The short and long integers would usually occupy two and four bytes respectively. Format
specifier for short int is %hd and long int is %ld.

signed and unsigned (modifiers)

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).

char data type


A single character can be defined as a character (char) type data. A char data type
occupy one byte memory. The qualifier signed or unsigned may be explicitly applied to
char. A signed char has range from -128 to +127. An unsigned char has a range from 0 to
255. Format specifier for char data type is %c.
Formula to calculate the range of signed data types is 2n-1, and for unsigned data type is
2n where n is the number of bits occupied by the data type.

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 5


PCE Programming for Problem Solving 1FY3-06

float, double and long double


A float occupies four bytes and can store from -3.4e38 to +3.4e38. If this is insufficient
then C offers a double data type that occupies 8 bytes in memory and has a range from -
1.7e308 to +1.7e308. If this is also insufficient then there is a long double that occupies 10
(12 in VS Code, 16 in Linux gcc) bytes and has a range from -1.7e4932 to +1.7e4932.
Format specifier for float is %f, for double %lf and for long double is %Lf.

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.

Subject Teacher: Bhagirath Singh Chauhan # 9829275869 Page No.: 6

You might also like