PPS Chapter 2
PPS Chapter 2
Using A=10
USER High level
Language B=20
Writing C=A+B
Like C++, programs
communicate? Java, Python print(C)
Source
program
or Source
COMPUTER code
Compiler: A software which converts whole HLL program into binary languge program in one pass.
eg. C, C++ uses compiler
Interpreter: A software which converts HLL program into binary languge program line by line.
eg. Python uses Interpreter
Assembler: A software which converts Assembly level language program into binary languge
program.
eg. Assembly level language uses assembler.
Note: some languages use both compiler and interpreter.
eg. Java uses both compiler and interpreter.
C language:
-’c’ is an ANSI (American National Standard Institute)/ISO (International organisation for
standardization) standard and powerful programming language for developing real time applications
or softwares.
-’C’ is a structured programming language developed by Dennis Ritchie in 1972 at AT&T Bell
laboratories, USA.
-’c’ language was developed to write the UNIX operating system.
History of C language:
Language Year Developed by
Algol 1960 International Group
BPCL 1967 Martin Richard
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K&RC 1978 Brian Kernighan and Dennis Ritchie
ANSI C 1989 ANSI commitee
ANSI C/ISO C 1990 ISO commitee
C99 1999 ISO commitee
- C language has evoled from three atructured programming languages i.e. ALGOL, BPCL and B.
- In 1978, Dennis Ritchie and Brian Kernighan published first version of C language.
- In 1983, ANSI established commitee to provide a modern, comphrehensive definition of c. The
resulting definition (“ANSI C”) was completed in 1988.
-In 1989, first version of “ANSI C” was published.
-In 1990, ISO standard published.
Features of C language:
-C as a mother language: c is considered as a mother language of all the modern programming
language because most of the compilers, JVM, kernels are written in c language and most of the
programming language follow c syntax.
eg. C++, Java, C# follows same C syntax.
It provides the core concepts like array, strings, functions, file handling that are being used in many
languages like C++, Java, C#.
-C as a system programming language: A system programming language is used to create
software. C is a system programming language because it can be used to do low level programming
(eg. Driver and kernel). It is generally used to create operating system, drivers, kernels.
eg. Linux operating system is written in C language.
-C as a structured programming language: In C language, we break the large program into parts
using functions. It makes program easier to understand and modify.
-C provides rich library of built in functions: C language defines large number of built in
functions to perform input/output operations, mathematical operations, string manipulation
operations.
-c language provides powerful concepts like pointer, recursion: using pointer we can manage
memory locations, recursion means calling itself.
-C language provide dynamic memory allocation:dynamic memory allocation means assigning
memory at runtime. C provides built in functions to allocate memory at runtime.
-C is a very simple language to learn and program.
HLL types:
structured programming language:
- In this type of language large programs are divided into small programs called functions.
-Prime focus is on functions and procedures that operate on data.
eg. C, pascal
Object oriented programming language:
- In this type of language large programs are divided into objects.
-Prime focus is in data that is being operated and not on functions or procedures.
eg. Java, C++, Python, C#
No structure oriented programming language:
-In this type of language no specific stucture is followed to write program.
eg. BASIC, COBOL, FORTRAN
• C character set:
The character set is the fundamental raw-material of any language. The character set is used to build
a program.
C language consist of two character sets:
1. source character set: It is useful to construct the statements in the source program. This set
includes three types of sysbols:
a. Alphabets: A...Z and a...z
b. decimal digits:0...9
c. special sysbol:+,-,* (asterisk), ~ (tilde),| (pipe),/ (forward slash), \ (backward slash), . (dot), ,
(comma),@ (at the rate), <, >, ?, ! ,$,#,& (ampersand),=,_ (underscore), ‘ ,”,[ (left bracket), ] (right
bracket),{ ( left brace),}(right brace),( (left parenthesis),) (right parenthesis), % ,^ (cap, caret),:,;
2. Execution character set: This set of characters are also called non-graphic character because
these are invisible and can not be printed or displayed directly. These are used to format output or to
fix the position of cursor. These characters will have effect only when program being executed.
Execution Character Meaning Result at the execution
\n End of line or Transfer the active position of cursor to the initial position
new line of next line.
\t Horizontal tab Transfer the active position of cursor to the next Horizontal
tab.
\v Vertical tab Transfer the active position of cursor to the next Vertical
tab.
\r Carriage return Transfer the active position of cursor to the initial position
of current line.
\f Form feed Transfer the active position of cursor to the next logical
page.
\0 (zero) End of string Null
• Delimiters (terminator): These are some special symbols used for termination.
Symbol Meaning Use
; Semi colon Used to teminate c statement
eg. int i;
, Comma Used to seperate variables,
constants.
eg. int i,j;
() Parenthesis Used for expression, used with
function to provide arduments
eg. c=(a+b)/(i-j);
eg. void main(int i)
{
}
[] Square bracket Used along with array
eg. int a[10];
{} Curly braces Used for blocking of statements
: Colon Used as label delimiter
# Hash Used as a pre-processor
directive
• Constants: Data item which never change its value during program execution.
Constant types:
1. Numeric constant: consists of numbers and optional sigh and optional dot (.) operator.
a. Integer constant: A whole number without fraction. eg. 123 is a integer, 1466987 is a
integer.
Integer constants are divided into three types based on number system:
i. Decimal integer constant: It is a sequence of one or more digits [(0...9) the digits of
decimal number system]. It may have optional + or – sign. eg. -123, 123
ii. Octal integer constant: It is a sequence of one or more digits [(0...7) the digits of
octal number system]. It may have optional + or – sign. It sholud start with the digit 0. eg. 0123
iii. Hexadecimal integer constant:It is a sequence of one or more digits/symbols
[(0...9,A,B,C,D,E,F) the symbols of Hexadecimal number system]. It may have optional + or – sign.
It sholud start with the digit 0x or 0X. eg. 0X123, 0x1F
b. real constant (floating point constant):The number with fraction is called floating point
number.
eg. 123.1 is a floating number.
The real number is written using two forms:
a. Fractional form: Must have at least one digit, a decimal point. It may have optional + or – sign.
eg. 12.01, 0.00000056
b. Exponential form:
0.00000056=>0.56*10-6=>0.56E-6
56000000=>0.56*108=>0.56e8
A real constant represented in exponential form has two parts: 1. Mantissa part : left side of e, 2.
exponent part: right side of e
2. Non-numeric constant (character constant)
a. single character constant: Any character enclosed with in single quotes (‘’) is called
character constant.
-Character constant may be single alphabet, single digit or single special symbol enclosed in single
quote.
eg. ‘A’
eg. ‘*’
eg. ‘5’
- Character constant has a maximum of 1 character.
b. multiple character constant (String constant): A string constant is a sequence of
alphanumeric characters enclosed in double quotes whose maximum length is 255 characters.
eg. “DGH”
eg.”123”
eg. “My mobile number is 7588086297”
eg.”DGH@123”
• Keywords (Reserve words): The C keywords are the reserved words by the compiler.
These words are reserved to do the specific tasks. All keywords have been assigned fixed
meaning. Compiler knows meaning and use of these words. C has total 32 keywords.
auto do goto
break double if
case else int
char extern long
continue float register
default for return
short sizeof static
struct switch typedef
union unsigned void
while const signed
volatile enum
unsigned declaration:
To declare unsigned short integer we can use one of the following declaration:
1. unsigned short a;
2. unsigned short int a;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Lo
wer
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 655 hig
36 her
327 163 819 409 204 102 512 256 128 64 32 16 8 4 2 1
68 84 2 6 8 4
Variable: A data item which can be change its value during the execution of program is called
variable.
Variable are called “named memory location”.
Variable in program is used to store and manipulate data.
Rules for defining variables:
1. The name of variable should not start with digit. It can start with letter or underscore.
eg. int a, int a1, int _a, int a_1 =>correct
int 1a, int 1_a =>wrong
2. The variable name should not be a C keyword.
3. The variable name length should be less than 31 characters.
4. You can use upper case, lower case, combination of upper and lower case, combination of
alphabets with digit and underscore to give name of variable.
eg. int b, int b1, int b_1, int Ab, int A, int Ab1, int _ab
where,
const=> keyword
data_type => types of data (int, float....)
constant_name => name of constant