C Language Fy Bca
C Language Fy Bca
HISTORY OF C
ALGOL
The root of all modern languages is ALGOL. ALGOL
is introduced in the early 1960s. ALGOL was the first
computer language to use a block structure. ALOGL
was widely used in Europe. ALGOL language gave the
concept of structured programming to the computer
science community.
HISTROY OF C
BCPL
In 1967, Martin Richards developed a language called
BCPL. The full form of BCPL is Basic Combined
Programming Language. BCPL was developed
primarily for writing System software.
HISTROY OF C
B
In 1970, Ken Thompson developed a language called
B at Bell Laboratory. Language B has been developed
using many features of BCPL.
C
C was evolved from ALGOL, BCPL and B. Dennis
Ritchie has developed C Language at Bell Laboratory
in 1972. C uses many concepts of ALGOL, BCPL and B
languages and added the concept of data types and
other powerful features. Unix operating system,
which was also developed at Bell Laboratory, was
coded almost entirely in C.
Today, C is running under a variety of operating
system and different hardware platforms.
HISTORY OF C IN SORT
Year Language Developed By
1960 ALGOL International Group
1967 BCPL Martin Richards
1970 B Ken Thompson
1972 C Dennis Ritchie
1978 K&R C Kerningham and
Ritchie
1989 ANSI C ANSI Committee
Importance of C
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced
around the early 1970s.
The language was formalized in 1988 by the American
National Standard Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System
Programming Language.
Today's most popular Linux OS and RDBMS MySQL have
been written in C.
Advantages of C or
Characteristics of C
C is general-purpose structured programming language
that is powerful, efficient and compact.
C is a structured, high level and machine independent
language.
C allows software developers to develop programs
without worrying about the hardware platforms.
C is a strong language whose rich set of built-in functions
and operators can be used to write any complex
programs.
The C is well suited for writing both System Software and
Application Software.
Advantages of C or
Characteristics of C
C programs are efficient (Well-Organized or
Disciplined) and fast due to its variety of data types
and powerful operators.
C is highly portable. This means that C programs are
written for one computer can be run on another
computer.
Another important feature of C is its ability to extend
itself. A C program is basically a collection of
functions that are supported by the C library. We can
continuously add our own functions to C library.
Character set
The characters that can be used to form words, numbers
and expressions depend upon the computer on which
the program is run. However, a subset of characters is
available that can be used on most personal, micro, mini
and mainframe computers. The characters in C are
grouped into the following categories:
Letters
Digits
Special characters
White spaces
Character set
Letters White Spaces Special Characters
Uppercase A...Z Blank space , Comma & Ampersand
Lowercase a...z Horizontal tab . Period ^ Caret
Carriage return ; Semicolon * Asterisk
New line : Colon - Minus Sign
Form feed ? Question Mark + Plus Sign
’ Apostrophe < Less Than Sign
” Quotation Mark > Greater Than Sign
! Exclamation Mark ( Left Parenthesis
| Pipe ) Right Parenthesis
/ Slash [ Left Bracket
Digits \ Backslash ] Right Bracket
~ Tilde { Left Brace
All decimal digits 0...9 _ Under Score } Right Brace
$ Dollar Sign # Number Sign
% Percent Sign @ At the rate Sign
Basic structure of C programm
The C Program can be viewed as a group of building
blocks of called functions. A function is a subroutine
that may include one or more statements designed to
perform a specific task.
A C Program may contain one or more sections which
are shown in figure below :
Basic structure of C programm
Documentation Section
Linkage Section
Definition Section
Subprogram Section
Function 1
---
---
Function N
Basic structure of C programm
DOCUMENTATION SECTION
The documentation section consists of a set of comment lines giving the name of the
program, name of the author, Program definition and other details, which the programmer
would like to user later.
LINKAGE SECTION
The linkage section provides instructions to the compiler to link functions from the system
library.
DEFINITION SECTION
The definition section defines all symbolic constants.
GLOBAL DECLARATION SECTION
There are some variables those are used in more than one function. Such variables are called
global variables and are declared in the global declaration section that is outside of all the
functions. Global Declaration Section also declares all the user-defined functions.
Basic structure of C programm
main ( ) FUNCTION SECTION
Every C program must have one main( ) function section.
This section contains two parts, declaration part and
executable part. The declaration part declares all the
variables used in the executable part. There is at least one
statement in the executable part. These two parts must
appear between the opening and the 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.
Basic structure of C programm
SUBPROGRAM SECTION
The subprogram section contains all the user-defined
functions that are called in the main function. User-
defined functions are generally placed immediately
after the main function, although they may appear in
any order.
C TOKENS
In a paragraph of text, individual words and punctuation marks are called
tokens. Similarly, in a program the smallest individual units are known as C
tokens.
C programs are written using these tokens and the syntax of the language. C
has following six types of tokens:
C TOKENS
The logical operators && and || are used when we want to test more than one
condition (relational expression) and make decisions. An example is :
a > b && a > c
The logical expression given above is true only if a>b is true and a > c is true. If
either (or both) of them is false, the expression is false.
OPERATORS
ASSIGNMENT OPERATORS
SPECIAL OPERATORS
The sizeof operator is normally used to determine the lengths (size) of
operand. The operand may be a variable, a constant or a data type qualifier
It returns the number of bytes the operand occupies.
Examples:
m = sizeof(sum);
n = sizeof(long int);
OPERATOR PRECEDENCE AND ASSOCIATIVITY
Operator Description Associativity Rank
& Address
Sizeof Size of an object
(type) Type cast (conversion)
* Multiplication Left to right 3
/ Division
% Modulus
+ Addition Left to right 4
- Subtraction
<< Left shift Left to right 5
>> Right shift
< Less than Left to right 6
<= Less than or equal to
> Greater than
>= Greater than of equal to
== Equality Left to right 7
|= Inequality
& Bitwise AND Left to right 8
^ Bitwise XOR Left to right 9
| Bitwise OR Left to right 10
&& Logical AND Left to right 11
|| Logical AND Left to right 12
?: Conditional expression Right to left 13
= Assignment operators Right to left 14
* = /=%=
+= -=
^= |= &=
<<= >>=
, Comma operator Left to right 15
OPERATOR PRECEDENCE AND ASSOCIATIVITY