fundamentals of c language

21
Fundamentals Of C Language By Mr. K R Biradar Mr. V D Chavan Mr. D S Patil RC_1131 1

Upload: prof-k-r-biradar

Post on 16-Jan-2017

77 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Fundamentals of c language

Fundamentals Of C LanguageBy

Mr. K R BiradarMr. V D Chavan

Mr. D S Patil

RC_1131

1

Page 2: Fundamentals of c language

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 Variables used in C 7 Type Conversion in C Language8 Expression types9 Operator Precedence and Associativity10 Bit-wise operators in C11 Conditional statements.12 Scope rules

2

Page 3: Fundamentals of c language

Mr. K R Biradar(Slides 4 to 8)

3

Page 4: Fundamentals of c language

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

Page 5: Fundamentals of c language

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

Page 6: Fundamentals of c language

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

Page 7: Fundamentals of c language

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

Page 8: Fundamentals of c language

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

Page 9: Fundamentals of c language

Mr. V D Chavan(Slides 10 to 13)

9

Page 10: Fundamentals of c language

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

Page 11: Fundamentals of c language

Type conversion in C Language

11

Implicit conversion Explicit conversion

int A = 552;double B = A;

Double B = 552;int A = (int)B;

Page 12: Fundamentals of c language

Type Conversion

12

Float doubleLong

double

int Unsigned int

Long int

Page 13: Fundamentals of c language

Expressions types

13

Different types of expression based on operators position

infix expression

prefix expression

postfix expression

p+q +pq Pq+

Page 14: Fundamentals of c language

Mr. D S Patil(Slides 15 to 20)

14

Page 15: Fundamentals of c language

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 = 10 + 4/ 2;

Here k is assigned 12, after execution of above statement• The Operator which will be having higher priority in

expression is evaluated first.

Page 16: Fundamentals of c language

• 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

Page 17: Fundamentals of c language

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

Page 18: Fundamentals of c language

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.

Page 19: Fundamentals of c language

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.

Page 20: Fundamentals of c language

Scope Rules #include<stdio.h> int d ; /*declaration of global variable*/ int main () { /* local variable declaration */ int e=10, f=20; d = e+ f; printf (“ e = %d, f = %d,d = %d \n“ ,e, f, d); return 0; }

Page 21: Fundamentals of c language

Thank You

21