Presentation is loading. Please wait.

Presentation is loading. Please wait.

11/10/2018.

Similar presentations


Presentation on theme: "11/10/2018."— Presentation transcript:

1 11/10/2018

2 Unit I Introduction to C
Contents : Operators ,control structures, enumeration ,structure , union, macros , arrays ,functions and parameter passing in C ,scope rules , string manipulation , matrix operations. Objective : To understand the basic building blocks of C language. To make the student comfortable in understanding the structure of the language. To inspire the students for simple problem solving and inculcating problem tackling skills 11/10/2018

3 Introduction to C Operators Functions and parameter passing in C
control structures Enumeration Structure Union Macros Functions and parameter passing in C Arrays Scope rules String manipulation , 11/10/2018

4 Introduction to C Motivation behind computers
It is an electronic machine Alan Turing's shorthand codes Developed by Dennis Ritchie Flexible in nature Procedure oriented language Follows top down approach 11/10/2018

5 Operators in C Operators and Operands
Operators are the special symbols which are used to indicate the type of operation operands are the data member or variables operating as per operation specified by operator. One expression contains set operators and operands There are six types of operator 11/10/2018

6 Arithmetic Operator operators which are useful in performing mathematical calculations. + : Used to add two operands - : Used to subtract two operands *: Used to multiply two operands /: Used to divide two operands %: Find reminder of the division of two operand To understand the operation assume variable A contains value 10 and variable contains value 5. 11/10/2018

7 Arithmetic Operator 11/10/2018

8 Relational Operator operators which are useful in performing mathematical calculations. > : < =: >=: ==: !=: To understand the operation assume variable A contains value 10 and variable contains value 5. 11/10/2018

9 Relational Operator 11/10/2018

10 Logical Operator operators which are useful in performing mathematical calculations. && : This is logical AND, it returns true when both the values are non zero ||: This is logical OR, it returns true when any of two value is non zero !: This is logical NOT operator, it is used to reverse the logical state of operand To understand the operation assume variable A contains value 10 and variable contains value 5. 11/10/2018

11 Logical Operator 11/10/2018

12 Other Operators Assignment Operators
Increments and Decrement Operators Bitwise Operators: work on the binary data. & | ^ To understand the operation assume variable A contains value 10 and variable contains value 5. 11/10/2018

13 Bitwise Operators 11/10/2018

14 Control Structures in C
Responsible to determine the sequence of other instructions in the program and for the reusability of the code Conditional Branching: if-----else statement switch statement Unconditional Branching: Break statement Goto statement: Continue statement Return statement 11/10/2018

15 Conditional Branching
11/10/2018

16 Control Structures in C
Responsible to determine the sequence of other instructions in the program and for the reusability of the code Conditional Branching: if-----else statement switch statement Unconditional Branching: Break statement Goto statement: Continue statement Return statement 11/10/2018

17 if-----else statement:
if (condition)           statement1           statement2 if-----else statement: if (condition) statement1; else statement2; 11/10/2018

18 switch statements: switch(expression) { case constant1: statements 1;
break; case constant2: statements 2; ………………….. default: statements n; } 11/10/2018

19 Unconditional Branching
Break statement: transfer the flow of program outside the loop or “switch” statement break; Goto statement: transfer the flow of program to any part of program           goto label name; label name : statement Continue statement: flow of program to the loop control instruction. Return statement : terminates the execution of the current function and return control to the calling function. 11/10/2018

20 Enumeration in C language
‘act of counting’ defined by using keyword ‘enum’ By default indexing of enumeration starts with ‘0’ enum identifier {enumerator list}; enum identifier object-name; 11/10/2018

21 Structures in C language
‘user define data type struct structure_name { structure element1; : :….. }; 11/10/2018

22 union in C language ‘user define data type union union _name {
union element1; : :….. }; 11/10/2018

23 Macros in C language ‘Macro represents the majorly used instruction in the program’ Macros are expanded by the C preprocessor. # define symbolic-name constant Example: # define pi 3.14 11/10/2018

24 Arrays in C language: Array is a data structure which stores the collection of similar types of element Indexing of array always start with ‘0’ data type array name[Maximum size]; 11/10/2018

25 Control Structures in C
Responsible to determine the sequence of other instructions in the program and for the reusability of the code Conditional Branching: if-----else statement switch statement Unconditional Branching: Break statement Goto statement: Continue statement Return statement 11/10/2018

26 Functions And Parameter Passing In C language:
block of code which is used to perform a specific task Functions are useful to divide c programs into smaller modules. function definition present outside the main function Return Type Function name (Argument list) { Statement 1; Statement 2; …………... Statement n; } 11/10/2018

27 Parameter passing by value: :
#include <stdio.h> #include<conio.h> /* function declaration goes here.*/ void swap( int p1, int p2 ); int main() { int a = 10; int b = 20; printf("Before: Value of a = %d and value of b = %d\n", a, b ); swap( a, b ); printf("After: Value of a = %d and value of b = %d\n", a, b ); getch(); } 11/10/2018

28 Parameter passing by value:
void swap( int p1, int p2 ) { int t; t = p2; p2 = p1; p1 = t; printf("Value of a (p1) = %d and value of b(p2) = %d\n", p1, p2 ); } Output : Before: Value of a = 10 and value of b = 20 Value of a (p1) = 20 and value of b (p2) = 10 After: Value of a = 10 and value of b = 20 11/10/2018

29 Parameter passing by reference: :
#include <stdio.h> #include<conio.h> /* function declaration goes here.*/ void swap( int p1, int p2 ); int main() { int a = 10; int b = 20; printf("Before: Value of a = %d and value of b = %d\n", a, b ); swap( a, b ); printf("After: Value of a = %d and value of b = %d\n", a, b ); getch(); } 11/10/2018

30 Parameter passing by reference: :
void swap( int *p1, int *p2 ) { int t; t = *p2; *p2 = *p1; *p1 = t; printf("Value of a (p1) = %d and value of b(p2) = %d\n", *p1, *p2 ); }  Output :  Before: Value of a = 10 and value of b = 20 Value of a (p1) = 20 and value of b(p2) = 10 After: Value of a = 20 and value of b = 10 11/10/2018

31 String Manipulation in C language:
Strings are also called as the array of character. A special character usually known as null character (\0) is used to indicate the end of the string. To read and write the string in C program %s access specifier is required. 11/10/2018

32 String Manipulation in C language:
11/10/2018


Download ppt "11/10/2018."

Similar presentations


Ads by Google