You are on page 1of 50

C is Programming Language

Developed at AT & Ts Bell Laboratory in 1972


Designed and Written by Dennis Ritchie
Replaced more familiar language like PL/I,
ALGOL etc.
Reliable, Simple and easy to use.
Nobody can learn directly C++/ Java directly
C++, C# or JAVA make use of object oriented
programming to organize program
Major parts of popular OS like windows, Linux
are still written in C
Common consumer devices like microwave
ovens, washing machines and digital cameras
program part is written in C
Some of 3D computer games
VARIABLES
Variables is entity that may change
Variable is nothing but the name given to the
memory cell
CONSTANTS
Constant is an entity that doesnt change
KEYWORDS
Reserved Words
Keywords are the words whose meaning has
already been explained to the C Compiler
Keywords cannot be used as variable names.
32 Keyword available in C.
An integer constant must have atleast one digit
It must not have decimal point
It can be either positive or negative
If no sign precedes an integer constant, it is
assumed to be positive
No commas or blanks are allowed within an
integer constant
The allowable range for integer constant is -
32768 to 32767 (assuming 16bit Compiler)
An integer constant must have atleast one digit
It must have decimal point
It can be either positive or negative
Default sign is positive.
No commas or blanks are allowed within an
integer constant
The mantissa part and exponent part should be
separated by a letter e or E
The mantissa part can be positive or negative
Default sign for mantissa is positive
The exponent part must have atleast one digit
which must be a positive or negative integer.
Default sign is positive
Any single alphabet, single digit or a single
special symbol enclosed within single inverted
commas.
Both inverted commas should point to left
Variable name is any combination of 1 to 31
alphabets, digits or underscores.
The first character in the variable name must be
an alphabet or underscore
No commas or blanks are allowed within
variable name
No special symbol other than an underscore
C compiler expects from user to specify type of
variable user want to use in program
This declaration is done at the beginning of
program
Eg. int a, float akc, char code
Different types of data allowed to be used in C
language
Primary data types are
o Integer
o Float
o Character
Some modifiers are allowed in C which gives
multiple sub class of data types
Such modifiers are like long, short, signed,
unsigned, double, long double etc..
Character occupies 1 byte memory location
Example for character variable declaration
Signed character (Range is -128 to 127)
Unsigned character (Range is 0 to 255)
Format specifier is %c.
Integer
Short

Long

For 16 bit compiler


2^16=65536
So Range is -32768 to +32767
For 32 bit compiler
2^32=4294967296
So range is -2147483648 to 2147483648
Five modifiers used for this are
Integer

Long

Short

Unsigned

Signed

For 16 bit compiler


Int a; (2byte)
a= 32800
Will not work as it is above 32767
long int a; (4byte)
a= 32800
Will work as it is falls in the range of -2147483648
to 2147483648
Signed
Unsigned
Float occupies 4bytes in memory
-3.4e38 to +3.4e38 (6 digits after decimal point)
Double occupies 8bytes in memory

-1.7e308 to +1.7e308 (12 digits after decimal point)


Long double occupies 10bytes in memory

-1.7e4932 to +1.7e4932 (19 digits after decimal


point)
Assignment Operators
= is an assignment operator
a=15

a=b=c=15

a+=15
Auto Incremenr/ Decrement Operators
These operators are ++, --,
The operator ++ adds 1

The operator subtracts 1

Two types: Prefix and Postfix auto


increment/decrement
Prefix a=5 b=5
b=++a
After Execution a=6 b=6
Postfix
a=5 b=5
b=a++
After execution a=6 b=5
+ addition
- subtraction
* Multiplication
/ division
% modulo
==
Checks if values of two operands are equal or not.
If yes then condition becomes true
!=

Checks if values of two operands are equal or not.


If no then condition becomes true
>

Checks value of left operand is more than right


operand. If yes then condition is true
<
Checks whether right operand is more than left
operand. If yes then condition is true.
>=

<=
AND &&
OR ||
NOT !
AND and OR operators allow two or more
conditions to be combined in if statement.
Not operator reverses the result of an
expression it operates on. The output is logical
value i.e. 0 or 1.
AND &
OR |
1s complement operator ~
XOR operator ^
Left shift operator <<
Right shift operator >>
Also called as Ternary Operator (?:)
Max=a>b?a:b
One Expression may contain different
operators
Precedence means the order in which the
operations are carried out for given
expression.
Associativity comes into picture when
operators of same priority comes into
expression.
printf(format specifier, variable list);

scanf(format specifier, variable list);


if (condition/expression)
{ statement1;
stetement2;
..
}
If only one statement present, then there is no
need of curly bracket. But though they are
present there wont be an error.
if (condition/expression)
{ statement1;
statement2;
.
}
else
{
Statement1;
Statement2;
.
}
if(condition/expression)
{ statement1;
. }
elseif(condition/expression)
{ statement1;
.}
elseif(condition/expression)
{statement1;
}
If (condition)
{
if (condition)
{
statement1;
.
}
else
{
statement1
..
}
else
{
Statement1

}
Syntax

while(condition)
{
statement1;
statement2;

}
Syntax

do
{ statement1;
Statement2;
} while(condition);
Syntax

for (initial counter; test counter; increment counter)


{
statement1;
statement2;.
}
switch(integer expression)
{
case constant1:
statement;
case constant2:
statement;
case constant3:
statement;
default:
statement;
}
switch(integer expression)
{
case constant1:
statement;
break;
case constant2:
statement;
break;
case constant3:
statement;
break;
default:
statement;
}
Array is a collective name given to group of
memory location containing similar data types.
Array is a collection of similar elements.
Similar elements could be all int, or all float or
all char, etc.
Array of character is called as string.
int marks[30]

int salary[6]= {24,45,56,56,56,76}

int salary[]= {24,45,56,56,56,76}

You might also like