C LANGUAGE - BESTECH SOLUTIONS
-
Upload
bestech-solutions -
Category
Technology
-
view
158 -
download
0
Transcript of C LANGUAGE - BESTECH SOLUTIONS
![Page 1: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/1.jpg)
Programming
![Page 2: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/3.jpg)
Control Statements
Complex Data Types
6 Input & Output Operations Agenda
7
8
9
10
Functions
Storage Class Specifier
![Page 4: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/4.jpg)
Dynamic Memory Allocation
File Management
11 Pointers Agenda
12
13
14
15
Programming Adages
Post Assessment Test
![Page 5: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/5.jpg)
Programming LanguageIntroduction
![Page 6: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/6.jpg)
History of CIntroduction
C
B
BCPL
ALGOL
![Page 7: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/7.jpg)
Portability Modularity
Flexibility
Extendability
Speed
Introduction Features of C
![Page 8: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/9.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/10.jpg)
• “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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/11.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/12.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/13.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/14.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/15.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/16.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/17.jpg)
• Branches– if…else – switch
• Loop– for– while – do…while
• Jump– goto– break– continue– exit
Control Statements
![Page 18: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/18.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/19.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/20.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/21.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/22.jpg)
• goto
• break
• continue
• exit
JumpControl Statements
![Page 23: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/23.jpg)
• Complex data types are made up of basic primitive data types.
Complex Data Types
Types
Array String Structure
![Page 24: C LANGUAGE - BESTECH SOLUTIONS](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/24.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/25.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/26.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/27.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/28.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/29.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/30.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/31.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/32.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022062523/58ef70241a28ab0c578b4569/html5/thumbnails/33.jpg)
THANK YOU !!!