Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views7 pages

Demo 1

fdh

Uploaded by

govindanm223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Demo 1

fdh

Uploaded by

govindanm223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

1 OVERVIEW OF C
1.1.1 History of C
In 1967, Martin Richards developed a language called BCPL. (Basic
Combined Programming Language). In 1970, ken Thompson created a
language using many features of BCPL and called it simply B. C was evolved
from ALGOL, BCPL, and B by Dennis Ritchie at Bell laboratories in 1972.

1.1.2 Importance of C
It is a robust language. It is rich in set of built-in functions and
operators that can be used to write any complex program. The C compiler
combines the capabilities of an assembly language with the features of a
high-level language. It was well suited for writing both system software and
business packages.

Programs written in C are efficient and fast. C is highly portable. C


programs written for one computer can be run on different with little or no
modification. Portability is important if we want to use computer with
different operation system. C language is well suited for structured
programming. Another important feature of C is its ability to extend itself.

1.1.3 Basic Structure of C Programs


Program can be viewed as a group of building blocks called functions.
Functions are subroutine that may include one or more statements designed
to perform a specific task. A C program may contain one or more sections.

DOCUMENTATION SECTION

1
LINK SECTION

DEFINITION SECTION

GLOBAL DECLARATION SECTION

main() Function Section


{
Declaration Part
Execution Part
}

Subprogram section
Function1
Function2
----
----
Function

(User-defined functions)

The documentation section consists of a set of comment lines giving


the name of the program, the author and other details which the
programmer would like to use later. The link section provides instructions to
the compiler to link functions from the system library. The definition section
defines all symbolic constants.
Global section which is outside of all functions used to declare
variables used in more than one function.

2
Every C program must have main() function section. The section
contains two parts namely declaration part and executable part. The
declaration part declares all the variables used in the executable part. There
should be one statement in the executable part.
The two parts must appear between opening and closing braces. The
program execution begins at the opening brace and ends at the closing
brace. The closing brace of the main function section is the logical end of the
program. All statements in the declaration and executable parts end with a
semicolon.
The subprogram section contains all the user-defined functions that
are called in the main function. All section except the main function section
may be absent when they are not required.
1.2 CONSTANTS, VARIABLES AND DATA TYPES
1.2.1 Character Set
The characters can be used to form words, numbers and expressions.
The character set in C are:
 letters A – Z (Uppercase) , a – z (Lowercase)
 Digits 0-9
 Special characters ( , comma ; semicolon etc. )
 White spaces,
 Blank space , horizontal tab, carriage return, new line, form feed.

3
Trigraph Characters:-
Each trigraph sequence consists of three characters i.e, two question
marks followed by another character.
??= # number sign ??( left bracket [ ??) right
bracket[
??< { left brace ??> } right brace ??!
vertical bar
??/ \ back slash ??’ ^ caret ??_ ~ tilde
1.2.2 C Tokens
The smallest individual units are known as tokens. C has six
types of tokens as shown in figure:

C TOKENS

STRINGS
KEYWORDS OPERATORS
CONSTANTS IDENTIFIERS

SPECIAL SYMBOLS

Special symbols [ ] {}
Keywords - float, while
Constants - 15.0, 100
Identifiers - main, amount
Strings - “ABC”, “YEAR”
Operators - +, - , *

4
1.2.3 Keywords and Identifiers
 All keywords have fixed meanings and these meanings cannot be
changed.
 All keywords must be written in lower case.
 Ex: auto, int, float, for, if , struct, do, char, long
Identifiers:-
Identifiers refer to the name of variables, functions and arrays. They
are user defined names.
Rules for Identifiers:-
 It consists of sequence of letters, digits with a letter as a first
character.
 Both uppercase and lower case letters are permitted, underscore is
also permitted.
 Only first 31 characters are significant.
 Cannot use a keyword.
 Must not contain white space.

1.2.4 Constants
It refers to fixed values that do not change during the execution of a
program. C supports several types of constants as shown in fig:

CONSTANTS

NUMERIC CHARACTER

INTEGER REAL SINGLE CHARACTER


STRING

5
a) Integer Constant
 An integer constant refers to a sequence of digits. There are
three types of integers called decimal, octal, and hexadecimal.
Integer constant

Decimal Octal Hexadecimal

i) Decimal Constant
 Decimal integers consists of set of digits 0-9 , preceded by an
optional - or + sign.
Ex: 123, - 123
 Embedded spaces, commas and digit character are not
permitted between
digits.
Ex: 15,750 $’ 1000
ii) Octal
 An octal integer constant consists of any combination of digits
from the set 0 – 7 with a leading zero.
Ex: 037 0
iii) Hexadecimal
 A sequence of digits (0-9) (A-F) by ox or OX is considered as
hexadecimal integer. They include alphabets A – F (or) a – f. A
– F represent from 10 – 15
Ex OX2 ox OXbcd
b) Real Constants
 The number followed by a decimal point and the fractional part
is known as real Constants.
Ex 215. -.71
 It may be expressed in exponential
Mantissa e exponent
6
 The mantissa is either a real number or an integer. Exponent is
an integer number with an optional + or - sign.

0.65e4 12e-2 3.18e3 -1.2 e-1

c) Single Character Constants

 A single character constant contains a single character enclosed


by a pair of single quote marks.
Ex : ‘5 ‘ ‘ X‘ ‘; ‘ ‘ ‘
d) String constants

 A string constant is a sequence of character enclosed in double


quotes. The character may be letters, numbers, special
character, and blank space.

E x: “Hello “ “1987 “ “5+3”

1.2.5 Variables
 Variable is a data name used to store a data value. It may take
different values at different times during execution.
Rules used to denote the variables:-
 It must begin with a letter.
 ANSI recognizes a length of 31 characters.
 The length should not be more than 8 characters.
 Uppercase and lowercase are significant.
 Variables should not be a keyword. White space is not allowed.
Ex: value t_raise > valid
123 % 25th > invalid

You might also like