c language - bestech solutions

33
Programm ing

Upload: bestech-solutions

Post on 13-Apr-2017

157 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: C LANGUAGE - BESTECH SOLUTIONS

Programming

Page 2: C LANGUAGE - BESTECH SOLUTIONS

History of C

Features of C

Structure of Program

Elements of C Program

1 Introduction Agenda

2

3

4

5

Page 3: C LANGUAGE - BESTECH SOLUTIONS

Control Statements

Complex Data Types

6 Input & Output Operations Agenda

7

8

9

10

Functions

Storage Class Specifier

Page 4: C LANGUAGE - BESTECH SOLUTIONS

Dynamic Memory Allocation

File Management

11 Pointers Agenda

12

13

14

15

Programming Adages

Post Assessment Test

Page 5: C LANGUAGE - BESTECH SOLUTIONS

Programming LanguageIntroduction

Page 6: C LANGUAGE - BESTECH SOLUTIONS

History of CIntroduction

C

B

BCPL

ALGOL

Page 7: C LANGUAGE - BESTECH SOLUTIONS

Portability Modularity

Flexibility

Extendability

Speed

Introduction Features of C

Page 8: C LANGUAGE - BESTECH SOLUTIONS

Documentation sectionLink Section

Definition SectionGlobal Declaration Section

main( ) Function Section {

Declaration partExecution part

}

Subprogram sectionFunction 1Function 2

…Function n

Structure Of Program

Page 9: C LANGUAGE - BESTECH SOLUTIONS

• The smallest individual units are known as C Tokens.

• Types

– Keywords

– Identifiers

– Constants

– Strings

– Operators

Elements of C Program C Tokens

Page 10: C LANGUAGE - BESTECH SOLUTIONS

• “Keywords” are the words which have special meaning to the C compiler.

• Some of the keywords are:

– auto

– double

– long

– static

– float

– struct

Elements of C Program C Tokens - Keywords

Page 11: C LANGUAGE - BESTECH SOLUTIONS

• Identifiers are the names of user-defined variables.

• Rules for identifiers.

• Example of valid identifiers:

Total, a1, SUM1, s_name, _Num

• Example of invalid identifiers:

1SUM,$_name,no., Student name

Elements of C Program C Tokens - Identifiers

Page 12: C LANGUAGE - BESTECH SOLUTIONS

• Constants are fixed values and can not be changed at run time.

• Types

– Integer constants

– Floating-point constants

– Character constants

– String constants

Elements of C Program C Tokens - Constants

Page 13: C LANGUAGE - BESTECH SOLUTIONS

• String is the sequence of characters.

• Any sequence or set of characters defined within double quotation symbols is a string.

• Examples

– “Good”

– “12345”

– “#412,krishnanagar”

– “$”

Elements of C Program C Tokens - String

Page 14: C LANGUAGE - BESTECH SOLUTIONS

• Operators are the symbols that represents specific actions.

• Operands are the variables that can be manipulated.

• Types of operators

– Unary

– Binary

– Ternary

– Special

Elements of C Program C Tokens - Operators

Page 15: C LANGUAGE - BESTECH SOLUTIONS

• Data type (or datatype) is a classification identifying one of various types of data.

– int

– long int

– float

– double

– char

– long double

Variable Data

Elements of C Program C Tokens – Data Types

Page 16: C LANGUAGE - BESTECH SOLUTIONS

• C standard library is a standardized collection of header files and library routines.

• stdio.h is a header file for standard input-output operations.• The console I/O functions are:

– getchar( )

– putchar( )

– gets( )

– puts( )

– printf( )

– scanf( )

Input & Output Operations

Page 17: C LANGUAGE - BESTECH SOLUTIONS

• Branches– if…else – switch

• Loop– for– while – do…while

• Jump– goto– break– continue– exit

Control Statements

Page 18: C LANGUAGE - BESTECH SOLUTIONS

Branches• If Statement

– if(expression)

statement;

– if(expression)

statement1;

else

statement2;

• Switch– switch(expression)

{ case 1: statements;

break; case 2: statements;

break; default: statements;}

Control Statements

Page 19: C LANGUAGE - BESTECH SOLUTIONS

• The For statement provides a compact way to iterate over a range of values.

• Syntax:

– for(initialization; test; inc/dec)

{

Body of the loop;

}

For LoopControl Statements

Page 20: C LANGUAGE - BESTECH SOLUTIONS

• The while statement is used to continually execute a block of statements until a condition remains true.

• Syntax:

– while(condition)

{

Body of the loop;

}

While LoopControl Statements

Page 21: C LANGUAGE - BESTECH SOLUTIONS

• The do-while is similar to the while statement but the condition is checked at the end of each iteration.

• Whether a condition is true or false, the loop get executed at least once.

• Syntax:do {

Body of the loop;

}while(condition); 

do…while LoopControl Statements

Page 22: C LANGUAGE - BESTECH SOLUTIONS

• goto

• break

• continue

• exit

JumpControl Statements

Page 23: C LANGUAGE - BESTECH SOLUTIONS

• Complex data types are made up of basic primitive data types.

Complex Data Types

Types

Array String Structure

Page 24: C LANGUAGE - BESTECH SOLUTIONS

• An array is a set of values but all are of same basic data type.

• Syntax:

datatype arrayname[width];

• Types

– Single dimensional

– Two dimensional

– Multi dimensional

ArrayComplex Data Types

Page 25: C LANGUAGE - BESTECH SOLUTIONS

int array[5][5]; int array[5][5];for (int i=0; i < 5; i++) for(int i=0;i<5;i++)for (int j=0; j < 5; j++) for(int j=0; j<i; j++)array[i][j] = 1; array[i][j]=1;

Array TraversalComplex Data Types

Page 26: C LANGUAGE - BESTECH SOLUTIONS

• String is a null-terminated character array.

• Syntax:

char variable_name[size];

• String Manipulation:

– strlen( )

– strcat( )

– strcmp( )

– strcpy( )

– strrev( )

StringComplex Data Types

Page 27: C LANGUAGE - BESTECH SOLUTIONS

• Structure is a collection of dissimilar data types.• Syntax:

struct structure_name { data type member1; data type member2; … };

• union • typedef • enum• Nested Structure• Array of Structure

StructureComplex Data Types

Page 28: C LANGUAGE - BESTECH SOLUTIONS

• Function is a block of code that performs a specific task.

• Function Arguments.

• Function Prototypes:

– No Arguments and No Return Values.

– Arguments and No Return Values.

– Arguments and Return Values.

– No Arguments and Return Values.

• Recursive functions.

Functions

Page 29: C LANGUAGE - BESTECH SOLUTIONS

• Storage Class specifiers specify where the data is stored.

• It defines the default value, scope and the life time of a

variable.

• Four storage class specifiers:

• auto

• static

• register

• extern

• Syntax:

Storage-class-specifier datatype <variable-name>;

Storage Class Specifier

Page 30: C LANGUAGE - BESTECH SOLUTIONS

• Pointer is a variable that holds the address of another variable.

• Syntax:data type * <variable-name>;

• Operator:– & ( Address Operator )– * ( Addressed Operator)

• Pointers and Function:– Call by value– Call by reference

• Pointer of Pointer

Pointers

Page 31: C LANGUAGE - BESTECH SOLUTIONS

• Dynamic functions used in memory management.

• malloc( ) – ptr=(DataType*)malloc(byte-size);

• calloc( ) – ptr=(DataType*) calloc(n,elem-size);

• free( )– free(ptr);

• realloc( )– ptr=realloc(ptr,newsize);

Dynamic Memory Allocation

Page 32: C LANGUAGE - BESTECH SOLUTIONS

• A file is a collection of bytes stored on a secondary storage device.

• File Management functions are as follows:

– fopen() creates a new file and opens an existing file.

– fclose() closes a file which has been opened for use.

– getc() reads a character from a file

– putc() writes a character to a file

– fprintf() writes a set of data values to a file

File Management

Page 33: C LANGUAGE - BESTECH SOLUTIONS

THANK YOU !!!