‘
‘
C
C
’
’
Language
Language
And
And
‘
‘
C
C
’
’
Program.
Program.
Why
‘
‘
C
C
’
’
•
•
Implements basic programming languages Implements basic programming languages concepts.concepts.
•
•
Structured programming language.Structured programming language.•
•
Developments of other PL requires core C Developments of other PL requires core C elements.elements.
•
•
Unix, Linux and Windows in C.Unix, Linux and Windows in C.•
•
Cellular phones and palmtop softwares.Cellular phones and palmtop softwares.•
•
Gaming frameworks.Gaming frameworks.•
•
Hardware devices interaction with max Hardware devices interaction with max performance.Alphabets, Digits, Special Symbols. Constants, Variables, And Keywords Instructions Program.
C Constants.
C Constants.
•
•
Primary Constants.Primary Constants.Integer Constants. Integer Constants. Real Constants. Real Constants. Character Constants. Character Constants.
•
•
Secondary Constants.Secondary Constants. Array.Array.
Pointer.
Pointer.
Structures and Unions.
Structures and Unions.
Enum
•
•
Integer Constants.Integer Constants. e.g. 426 e.g. 426 +756 +756 --588 etc.588 etc.•
•
Character Constants.Character Constants. e.g. e.g. ‘‘EE’’ ‘ ‘hh’’ ‘ ‘==‘‘ ‘ ‘88’’•
•
Real Constants.Real Constants. e.g. 488.22e.g. 488.22 +3.211e+3.211e--44 +85.23
+85.23 5.6e45.6e4
Data types declaration.
Data types declaration.
int
int
a; /* General declaration */
a; /* General declaration */
int
int
a = 10; /* Valued Declaration */
a = 10; /* Valued Declaration */
float b = 12.6;
float b = 12.6;
float b;
float b;
char c;
char c;
char c =
char c =
‘
‘
y
y
’
’
;
;
Maximum values of Data Types.
Maximum values of Data Types.
•
•
intint requires 2 bytes to store in memory.requires 2 bytes to store in memory.--32768 to 32767.32768 to 32767.
•
•
floatfloat requires 4 bytes to store.requires 4 bytes to store.--3.4e38 to 3.4e38.3.4e38 to 3.4e38.
•
•
charchar requires 1 byte to store.requires 1 byte to store. AA…….Z and a.Z and a…….z also special symbols. .z also special symbols.
•
•
long long intint requires 4 bytes to store.requires 4 bytes to store.--2147483648 to 2147483647.2147483648 to 2147483647.
•
•
doubledouble requires 8 bytes to store.requires 8 bytes to store.--1.7e308 to 1.7e308.1.7e308 to 1.7e308.
•
•
long doublelong double requires 10 bytes to store.requires 10 bytes to store.Giving variable names (identifiers).
Giving variable names (identifiers).
•
•
‘
‘
C
C
’
’
is a case
is a case
-
-
sensitive language.
sensitive language.
means
means
‘
‘
a
a
’
’
≠
≠
‘
‘
A
A
’
’
.
.
•
•
All the alphabets are allowed.
All the alphabets are allowed.
•
•
All numbers are allowed but not at the
All numbers are allowed but not at the
start.
start.
e.g
e.g
char a9,
char a9,
thyy
thyy
; /* Valid */
; /* Valid */
char 5abc; /* Invalid */
char 5abc; /* Invalid */
•
•
Only special symbol _ (under score) is
Only special symbol _ (under score) is
allowed. e.g.
Keywords.
Keywords.
auto
auto
break
break
case
case
char
char
const
const
continue
continue
default
default
do
do
double
double
else
else
enum
enum
extern
extern
float
float
for
for
goto
goto
if
if
long
long
register
register
return
return
short
short
signed
signed
sizeof
sizeof
static
static
struct
struct
switch
switch
typedef
typedef
union
union
unsigned
unsigned
void
void
while
while
volatile
Operators.
Operators.
•
•
Numerial
Numerial
operators.
operators.
•
•
Logical operators.
Logical operators.
•
•
Relational operators.
Relational operators.
•
•
Conditional operators.
Conditional operators.
•
Numerical operators.
Numerical operators.
+
+
-
-
*
*
/
/
%
%
=
=
---e.g.
e.g.
int
int
a, y = 10, x = 12;
a, y = 10, x = 12;
float b;
float b;
a = y + 10;
a = y + 10;
b = x / 2;
b = x / 2;
a = a
a = a
–
–
b;
b;
Relational operators.
Relational operators.
> > < < >= >= <= <= == !=== !=Logical operators.
&& || && ||Conditional operators.
? ? ::Boolean operators.
& & | | ~ ~ ^^Expression and Statements.
Expression and Statements.
int int a = 10, j = 26;a = 10, j = 26; float r = 5.22, t = 2.66 + 45.2 * 2; float r = 5.22, t = 2.66 + 45.2 * 2; float b = 1.02 , c = b / 2 + 5.2; float b = 1.02 , c = b / 2 + 5.2; int int d, e, f, g;d, e, f, g; d = e = f= g = 50; d = e = f= g = 50;
float alpha = 23.001, beta = 892.00;
float alpha = 23.001, beta = 892.00;
float delta = alpha * beta / 3.2
float delta = alpha * beta / 3.2 – – alpha;alpha; char h, i ; char h, i ; h = h = ‘‘DD’’;; I = h; I = h;
Hierarchy of operations.
Hierarchy of operations.
int
int
i;
i;
i = 5 * 6
i = 5 * 6
–
–
8 + 9
8 + 9
–
–
(43 + 2) /5
(43 + 2) /5
–
–
5;
5;
i = 30
i = 30
–
–
8 + 9
8 + 9
–
–
45/5
45/5
–
–
5;
5;
i = 30
i = 30
–
–
8 + 9
8 + 9
–
–
9
9
–
–
5;
5;
i = 22 + 0
i = 22 + 0
–
–
5;
5;
i = 17;
i = 17;
First
First
‘
‘
C
C
’
’
Program.
Program.
#include<
#include<stdio.hstdio.h>> main() main() { { int int i = 10, j = 12;i = 10, j = 12; float k, m = 12.6; float k, m = 12.6; k = (i + j) / m; k = (i + j) / m; printf(
printf(““InputInput : %d : %d %d%d %f%f””, i, j, m);, i, j, m); printf(
printf(““\\nOutputnOutput : %f : %f ””, k);, k); } } Input : 10 12 12.600000 Input : 10 12 12.600000 Output : 1.746032 Output : 1.746032
Basic I/O statements.
Basic I/O statements.
•
•
printf
printf
.
.
printf
printf((““<formal string><formal string>””,<list of variables>);,<list of variables>); e.g.
e.g. printf(printf(““HelloHello worldworld””);); int
int i = 15; i = 15; printf(
printf(““ValueValue of i is : %dof i is : %d””, i );, i );
¾
¾ %d %d –– integer value.integer value.
¾
¾ %f %f –– float value.float value.
¾
¾ %c %c –– character valuecharacter value
printf(
Basic I/O statements.
Basic I/O statements.
•
•
scanf
scanf
.
.
It accepts values from user in the form of
It accepts values from user in the form of
int
int
/ float / char / long / double.
/ float / char / long / double.
e.g.
e.g.
int
int
j,
j,
char m;
char m;
float k;
float k;
scanf(
Compilation and Execution
Compilation and Execution
•
•
Integrated Development Environment
Integrated Development Environment
(IDE).
(IDE).
editor + compiler.
editor + compiler.
•
•
Compiling
Compiling
‘
‘
C
C
’
’
program
program
F9 / Alt F9
F9 / Alt F9
–
–
Compiling.
Compiling.
Ctrl F9
Ctrl F9
–
–
Executing.
Executing.
Alt F5
Created By,
Created By,
•
•
Mr.
Mr.
Tushar
Tushar
B
B
Kute
Kute
,
,
Lecturer in Information Technology,
Lecturer in Information Technology,
K. K.
K. K. WaghWagh Polytechnic, Nashik.Polytechnic, Nashik. [email protected]