Upload
prof-k-r-biradar
View
28
Download
0
Embed Size (px)
Citation preview
Fundamentals Of C LanguageBy
Mr. K R BiradarMr. V D Chavan
Mr. D S Patil
RC_1131
1
Contents1 Introduction to C Programming2 Fundamentals of C Compiling and Linking3 Basic Keywords in C4 Variable Storage and range used in C5 Different Data Types used in C6 Floating types in C7 Type Conversion in C8 Expression types9 Operator Precedence and Associativity10 Bitwise operators in C11 Conditional expressions.12 Scope rules
2
Mr. K R Biradar(Slides 4 to 8)
3
Important Features of C
a. It is a Low Level Language: Used
in system programming
b. C has standard in built functions
c. C language has a portability that can
run in different platform with no or
little modification in the program
INTRODUCTION TO PROGRAMMING C
Fundamentals of C Compiler and Linking
• Preprocessor Directives: The character starts with # in the program and which is different than the source code
• Compiler Program Modified Compiler Object Code
• Linker: Code used in the compiler to link other libraries
Basic Keywords in C
int float short longauto do do while sizeof
struct char typedef signed
union register void for
goto volatile continue static
If else double switch
break case return extern
Variable, storage and range used in C
Types of Variable
Sizeof Lowest Value
Highest Value
Int 2 bytes -32768 32767
Unsigned Char
1 byte 0 255
Signed char 1 byte -128 127
Unsigned int 2 bytes 0 65535
Different Data Types used in C• The different data types used in C language are• Int: (Integer) Used to declare variables of type
whole number• Char:(Character) Used to declare alphanumeric
characters• Float: (Floating Point Numbers) Used to declare
variables of type fractional numbers.• The variables used in C are long int, short int,
unsigned int, unsigned char etc
Mr. V D Chavan(Slides 10 to 13)
9
Floating points in C
10
Type Size Range
float 4 bytes 1.2e-38 to 3.4e +38
double 8 bytes 2.8e-308 to 1.7e+308
long double 16 bytes 3.4e-4932 to 1.1e+4932
Type conversion in C
11
Implicit conversion Explicit conversion
Int A = 552;Double B = A;
Double B = 552;Int A = (int)B;
Type Conversion
12
Float doubleLong
double
int Unsigned int
Long int
Expressions types
13
Different types of expression based on
operators position
infix expression
prefix expression
postfix expression
p+q +pq Pq+
Mr. D S Patil(Slides 15 to 20)
14
Operator Precedence and Associativity• Operator precedence helps for grouping of terms in an
expression and decides order in which an expression is evaluated.
• Some operators have higher priority than other operators.
• Associativity rule of an operator defines the order in which operators of the same precedence are evaluated in the absence of brackets.
eg: addition operator has a lower priority than division operation. K = 8 + 4/ 2;
Here k is assigned 10, after execution of above statement• The Operator which will be having higher priority in
expression is evaluated first.
• Below table show the higher to lower priority of the operators
from top to bottom of the table
Operator Precedence and Associatively
Category Operator AssociativityMultiplicative * / % Left to Right
Additive + - Left to RightShift << >> Left to Right
Relational < <= > >= Left to Right
Equality == != Left to Right
Bitwise AND & Left to RightBitwise XOR ^ Left to Right
Bitwise OR | Left to Right
Logical AND && Left to Right
Logical OR || Left to RightConditional ? : Right to Left
Bitwise operators in C• Bitwise operators perform bit by bit operation .
Bitwise Operators are: logical AND, logical OR and logical e exclusive OR.
Truth table
eg: A = 1100 , B = 1101 then A logical AND B =1100
P Q P&Q P|Q P^Q
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Conditional Expressions• Conditional Expressions Contains 3 operands and 2
operators ( ? And : ) are used. syntax condition? expression1:expression2 • If the result of condition is satisfied, first expression is
evaluated and the result of the evaluation becomes the result of the operation. If the condition is not satisfied, then second expression is evaluated and its result becomes the result of the operation.
Scope Rules• A scope in any programming is a region of the
program where a defined variable can have its existence and that variable cannot be accessed outside that region.
• Variables declared in functions are local variables.
• Variables declared out side the functions are global variables.
Scope Rules #include<stdio.h> int d ; /*declaration of global variable*/ int main () { /* local variable declaration */ int e, f; e = 10; f = 20; d = e+ f; printf (“ e = %d, f = %d , d = %d \n“ ,e, f, d); return 0; }
Thank You
21