SlideShare uma empresa Scribd logo
1 de 23
KALINGAINSTITUTEOFINDUSTRIALTECHNOLOGY
BHUBANESWAR ODISHA 751024
DEPARTMENT OF ELECTRONICS AND TELECOMMUNICATION
Industrial Training Report On
C Programming.
Submitted To Submitted By
Md Nadim Akber
Roll No: 1404294
Branch: ETC
Overview
 C is a general-purpose, high-levellanguage that was originally developed
by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs.
C was originally firstimplemented on the DEC PDP-11 computer in 1972.
In 1978 Brian Kernighan and Dennis Ritchie produced the firstpublicly
available description of C, now known as the K&R standard.
History of C Language Programming
1. C is a programming language which born at “AT & T’s Bell Laboratory” of
USA in 1972.
2. C was written by Dennis Ritchie, that’s why he is also called as father of c
programming language.
3. C language was created for a specific purpose i.e designing the UNIX
operating system (which is currently base of many UNIX based OS).
4. From the beginning, C was intended to be useful to allow busy
programmers to get things done because C is such a powerful, dominant
and supple language
5. Its use quickly spread beyond Bell Labs in the late 70’s because of
its long list of strong features.
Basics In C – Programming
Below are few commands and syntax used in C programming to write a simple
C program. Let’s see all the sections of a simple C program line by line.
C Basic commands Explanation
#include <stdio.h>
This is a pre-processor command that includes standard
input output header file(stdio.h) from the C library before
compiling a C program
int main()
This is the main function from where execution of any C
program begins.
{ This indicates the beginning of the main function.
/*_some_comments_*/
whatever is given inside the command “/* */” in any C
program, won’t be considered for compilation and
execution.
printf(“Hello_World!“); printf command prints the output onto the screen.
getch(); This command waits for any character input from keyboard.
return 0;
This command terminates C program (main function) and
returns 0.
} This indicates the end of the main function
Printf() and scanf() in C :
The printf() and scanf() functions are used for input and output in C language.
Both functions are inbuilt library functions, defined in stdio.h (header file).
printf() function
 The printf() function is used for output. It prints the given statement to
the console.
 The syntax of printf() function is given below:
printf("format string",argument_list);
 The format string can be %d (integer), %c (character), %s (string), %f
(float) etc.
scanf() function
 The scanf() function is used for input. It reads the input data from the
console.
 The syntax of scanf() function is given below:
 scanf("format string",argument_list);
Variables in C:
A variable is a name of memory location. It is used to store data. Its value can
be changed and it can be reused many times. It is a way to represent memory
location through symbol so that it can be easily identified.
The example of declaring variable is given below:
int a;
float b;
char c;
Here, a, b, c are variables and int,float,char are data types.
We can also provide values while declaring the variables as given below:
int a=10,b=20;//declaring 2 variable of integer type
float f=20.8;
char c='A';
Rules for defining variables
o A variable can have alphabets, digits and underscore.
o A variable name can start with alphabet and underscore only. It can't
start with digit.
o No white space is allowed within variable name.
o A variable name must not be any reserved word or keyword e.g. int,
float etc.
Types of Variables in C
There are many types of variables in c:
1. local variable
2. global variable
3. static variable
4. automatic variable
5. external variable
Local Variable
A variable that is declared inside the function or block is called local variable.
It must be declared at the start of the block.
You must have to initialize the local variable before it is used.
Global Variable
A variable that is declared outside the function or block is called global
variable. Any function can change the value of the global variable. Itis available
to all the functions.
It must be declared at the start of the block.
Static Variable
A variable that is declared with static keyword is called static variable.
It retains its value between multiple function calls.
If you call this function many times, local variable will print the same
value for each function call e.g, 11,11,11 and so on. But static variable
will print the incremented value in each function call e.g. 11, 12, 13
and so on.
Automatic Variable
All variables in C that is declared inside the block, are automatic variables
by default. By we can explicitly declare automatic variable using auto
keyword.
External Variable
We can share a variable in multiple C source files by using external
variable. To declare a external variable, you need to use extern
keyword.
Data Types in C:
A data type specifies the type of data that a variable can store such as integer,
floating, character etc.
There are 4 types of data types in C language.
Types Data Types
Basic Data Type int, char, float, double
Derived Data Type array, pointer, structure, union
Enumeration Data Type enum
Void Data Type void
Basic Data Types
The basic data types are integer-based and floating-point based. C language
supports bothsigned and unsigned literals.
The memory size of basic data types may change according to 32 or 64 bit
operating system.
Let's see the basic data types. Its size is given according to 32 bit architecture.
Data Types Memory Size Range
char 1 byte −128 to 127
signed char 1 byte −128 to 127
unsigned char 1 byte 0 to 255
short 2 byte −32,768 to 32,767
signed short 2 byte −32,768 to 32,767
unsigned short 2 byte 0 to 65,535
int 2 byte −32,768 to 32,767
signed int 2 byte −32,768 to 32,767
unsigned int 2 byte 0 to 65,535
short int 2 byte −32,768 to 32,767
signed short int 2 byte −32,768 to 32,767
unsigned short int 2 byte 0 to 65,535
long int 4 byte -2,147,483,648 to 2,147,483,647
signed long int 4 byte -2,147,483,648 to 2,147,483,647
unsigned long int 4 byte 0 to 4,294,967,295
float 4 byte
double 8 byte
long double 10 byte
Keywords in C:
A keyword is a reserved word. You cannot use it as a variable
name, constant name etc. There are only 32 reserved words
(keywords) in C language.
C Operators:
An operator is simply a symbol that is used to perform
operations. There can be many types of operations like
arithmetic, logical, bitwise etc.
There are following types of operators to perform different
types of operations in C language.
o Arithmetic Operators
o Relational Operators
o Shift Operators
o Logical Operators
o Bitwise Operators
o Ternary or Conditional Operators
o Assignment Operator
o Misc Operator
C Control Statements
Control statements is given below:
C if else Statement
The if statement in C language is used to perform operation on the basis of condition. By
using if-else statement, you can perform operation either condition is true or false.
There are many ways to use if statement in C language:
o If statement
o If-else statement
o If else-if ladder
o Nested if
If Statement
The single if statement in C language is used to execute the code if condition is true. The
syntax of if statement is given below:
1. if(expression){
2. //code to be executed
3. }
If-else Statement
The if-else statement in C language is used to execute the code if condition is true or
false. The syntax of if-else statement is given below:
1. if(expression){
2. //code to be executed if condition is true
3. }else{
4. //code to be executed if condition is false
5. }
If else-if ladder Statement
The if else-if statement is used to execute one code from multiple conditions. The syntax
of if else-if statement is given below:
1. if(condition1){
2. //code to be executed if condition1 is true
3. }else if(condition2){
4. //code to be executed if condition2 is true
5. }
6. else if(condition3){
7. //code to be executed if condition3 is true
8. }
9. ...
10. else{
11. //code to be executed if all the conditions are false
12. }
C Switch Statement
The switch statement in C language is used to execute the code from
multiple conditions. It is like if else-if ladder statement.
C Loops
The loops in C language are used to execute a block of code or a part of
the program several times.
In other words, it iterates a code or group of code many times.
Advantage of loops in C
1) It saves code.
2) It helps to traverse the elements of array
Types of C Loops
There are three types of loops in C language that is given below:
1. do while
2. while
3. for
do-while loop in C
It iterates the code until condition is false. Here, condition is given after the code. So at
least once, code is executed whether condition is true or false.
while loop in C
Like do while, it iterates the code until condition is false. Here, condition is given before
the code. So code may be executed 0 or more times.
It is better if number of iteration is not known by the user.
The syntax of while loop in c language is given below:
1. while(condition){
2. //code to be executed
3. }
for loop in C
Like while, it iterates the code until condition is false. Here, initialization, condition and
increment/decrement is given before the code. So code may be executed 0 or more
times.
It is good if number of iteration is known by the user.
The syntax of for loop in c language is given below:
1. for(initialization;condition;incr/decr){
2. //code to be executed
3. }
do while loop in C
To execute a part of program or code several times, we can use do-while loop of C
language. The code given between the do and while block will be executed until
condition is true.
In do while loop, statement is given before the condition, so statement or code will be
executed at lease one time. In other words, we can say it is executed 1 or more
times.
It is better if you have to execute the code at least once.
do while loop syntax
The syntax of C language do-while loop is given below:
1. do{
2. //code to be executed
3. }while(condition);
C Functions:
The function in C language is also known as procedure or subroutine in
other programming languages.
To perform any task, we can create function. A function can be called
many times. It provides modularity and code reusability.
Types of Functions
There are two types of functions in C programming:
1. Library Functions: are the functions which are declared in the C
header files such as scanf(), printf(), gets(), puts(), ceil(), floor()
etc.
2. User-defined functions: are the functions which are created by
the C programmer, so that he/she can use it many times. It reduces
complexity of a big program and optimizes the code.
Call by value and call by reference in C
There are two ways to pass value or data to function in C language: call
by value and call by reference. Original value is not modified in call by
value but it is modified in call by reference.
Call by value in C
In call by value, original value is not modified.
In call by value, value being passed to the function is locally stored by the function
parameter in stack memory location. If you change the value of function parameter, it is
changed for the current function only. It will not change the value of variable inside the
caller method such as main().
Call by reference in C
In call by reference, original value is modified because we pass reference (address).
Here, address of the value is passed in the function, so actual and formal arguments
shares the same address space. Hence, value changed inside the function, is reflected
inside as well as outside the function.
Recursion in C
When function is called within the same function, it is known
as recursion in C. The function which calls the same function, is known
as recursive function.
A function that calls itself, and doesn't perform any task after function
call, is know as tail recursion. In tail recursion, we generally call the
same function with return statement.
Storage Classes in C
Storage classes are used to define scope and life time of a variable. There
are four storage classes in C programming.
o auto
o extern
o static
o register
C Array:
Array in C language is a collection or group of elements (data). All the elements
of c array are homogeneous (similar). It has contiguous memory location.
Advantage of C Array
1) Code Optimization: Less code to the access the data.
2) Easy to traverse data: By using the for loop, we can retrieve the
elements of an array easily.
3) Easy to sort data: To sort the elements of array, we need a few lines of
code only.
4) Random Access: We can access any element randomly using the array.
Declaration of C Array
We can declare an array in the c language in the following way.
data_type array_name[array_size];
Two Dimensional Array in C
The two dimensional array in C language is represented in the form of rows and
columns, also known as matrix. It is also known as array of arrays or list of
arrays.
The two dimensional, three dimensional or other dimensional arrays are also
known as multidimensional arrays.
Declaration of two dimensional Array in C
We can declare an array in the c language in the following way.
1. data_type array_name[size1][size2];
Passing Array to Function in C
To reuse the array operation, we can create functions that receives array as argument.
To pass array in function, we need to write the array name only in the function call.
C Pointers:
The pointer in C language is a variable, it is also known as locator or indicator that
points to an address of a value.
Declaring a pointer
The pointer in c language can be declared using * (asterisk symbol).
int *a;//pointer to int
char *c;//pointer to char
NULL Pointer
A pointer that is not assigned any value but NULL is known as NULL pointer. If you don't
have any address to be specified in the pointer at the time of declaration, you can assign
NULL value. It will a better approach.
int *p=NULL;
In most the libraries, the value of pointer is 0 (zero).
C Pointer to Pointer
In C pointer to pointer concept, a pointer refers to the address of another pointer.
In c language, a pointer can point to the address of another pointer which points to the
address of a value. Let's understand it by the diagram given below:
Let's see the syntax of pointer to pointer.
int **p2;
Dynamic memory allocation in C
The concept of dynamic memory allocation in c language enables the C programmer
to allocate memory at runtime. Dynamic memory allocation in c language is possible by
4 functions of stdlib.h header file.
1. malloc()
2. calloc()
3. realloc()
4. free()
Before learning above functions, let's understand the difference between static memory
allocation and dynamic memory allocation.
static memory allocation dynamic memory allocation
memory is allocated at compile time. memory is allocated at run time.
memory can't be increased while executing program. memory can be increased while exec
used in array. used in linked list.
Now let's have a quick look at the methods used for dynamic memory allocation.
malloc() allocates single block of requested memory.
calloc() allocates multiple block of requested memory.
realloc() reallocates the memory occupied by malloc() or calloc() functions.
free() frees the dynamically allocated memory.
malloc() function in C
The malloc() function allocates single block of requested memory.
It doesn't initialize memory at execution time, so it has garbage value initially.
It returns NULL if memory is not sufficient.
The syntax of malloc() function is given below:
ptr=(cast-type*)malloc(byte-size)
calloc() function in C
The calloc() function allocates multiple block of requested memory.
It initially initialize all bytes to zero.
It returns NULL if memory is not sufficient.
The syntax of calloc() function is given below:
ptr=(cast-type*)calloc(number, byte-size)
realloc() function in C
If memory is not sufficient for malloc() or calloc(), you can reallocate the memory by
realloc() function. In short, it changes the memory size.
Let's see the syntax of realloc() function.
1. ptr=realloc(ptr, new-size)
free() function in C
The memory occupied by malloc() or calloc() functions must be released by calling free()
function. Otherwise, it will consume memory until program exit.
Let's see the syntax of free() function.
free(ptr)
C Strings:
String in C language is an array of characters that is terminated by 0 (null character).
There are two ways to declare string in c language.
1. By char array
2. By string literal
C gets() and puts() functions
The gets() function reads string from user and puts() function prints the string. Both
functions are defined in <stdio.h> header file.
C Structure Union:
Structure in c language is a user defined datatype that allows you to hold different
type of elements.
Each element of a structure is called a member.
It works like a template in C++ and class in Java. You can have different type of
elements in it.
Defining structure
The struct keyword is used to define structure. Let's see the syntax to define structure
in c.
1. struct structure_name
2. {
3. data_type member1;
4. data_type member2;
5. data_type memeberN;
6. };
Array of Structures in C
There can be array of structures in C programming to store many information of
different data types. The array of structures is also known as collection of structures.
Nested Structure in C
Nested structure in c language can have another structure as a member. There are
two ways to define nested structure in c language:
1. By separate structure
2. By Embedded structure
1) Separate structure
We can create 2 structures, but dependent structure should be used inside the main
structure as a member. Let's see the code of nested structure.
2) Embedded structure
We can define structure within the structure also. It requires less code than previous
way. But it can't be used in many structures.
C Union
Like structure, Union in c language is a user defined datatype that is used to hold
different type of elements.
But it doesn't occupy sum of all members size. It occupies the memory of largest
member only. It shares memory of largest member.
Advantage of union over structure
It occupies less memory because it occupies the memory of largest member only.
Disadvantage of union over structure
It can store data in one member only.
Defining union
The union keyword is used to define union. Let's see the syntax to define union in c.
1. union union_name
2. {
3. data_type member1;
4. data_type member2;
5. .
6. .
7. data_type memeberN;
8. };
File Handling in C:
File Handling in c language is used to open, read, write, search or close file. It is used
for permanent storage.
Advantage of File
It will contain the data even after program exit. Normally we use variable or array to
store data, but data is lost after program exit. Variables and arrays are non-permanent
storage medium whereas file is permanent storage medium.
Functions for file handling
There are many functions in C library to open, read, write, search and close file. A list of
file functions are given below:
No. Function Description
1 fopen() opens new or existing file
2 fprintf() write data into file
3 fscanf() reads data from file
4 fputc() writes a character into file
5 fgetc() reads a character from file
6 fclose() closes the file
7 fseek() sets the file pointer to given position
8 fputw() writes an integer to file
9 fgetw() reads an integer from file
10 ftell() returns current position
11 rewind() sets the file pointer to the beginning of the file
THANK YOU
Complete c programming presentation

Mais conteúdo relacionado

Mais procurados

Mais procurados (18)

C programming language
C programming languageC programming language
C programming language
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
 
C programming session6
C programming  session6C programming  session6
C programming session6
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
 
C++
C++C++
C++
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 

Semelhante a Complete c programming presentation

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdfRajb54
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoMark John Lado, MIT
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptxCarla227537
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDFSuraj Das
 

Semelhante a Complete c programming presentation (20)

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Basic c
Basic cBasic c
Basic c
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
C Language Presentation.pptx
C Language Presentation.pptxC Language Presentation.pptx
C Language Presentation.pptx
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptx
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C# AND F#
C# AND F#C# AND F#
C# AND F#
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 

Último

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Último (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Complete c programming presentation

  • 1. KALINGAINSTITUTEOFINDUSTRIALTECHNOLOGY BHUBANESWAR ODISHA 751024 DEPARTMENT OF ELECTRONICS AND TELECOMMUNICATION Industrial Training Report On C Programming. Submitted To Submitted By Md Nadim Akber Roll No: 1404294 Branch: ETC
  • 2.
  • 3. Overview  C is a general-purpose, high-levellanguage that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally firstimplemented on the DEC PDP-11 computer in 1972. In 1978 Brian Kernighan and Dennis Ritchie produced the firstpublicly available description of C, now known as the K&R standard. History of C Language Programming 1. C is a programming language which born at “AT & T’s Bell Laboratory” of USA in 1972. 2. C was written by Dennis Ritchie, that’s why he is also called as father of c programming language. 3. C language was created for a specific purpose i.e designing the UNIX operating system (which is currently base of many UNIX based OS). 4. From the beginning, C was intended to be useful to allow busy programmers to get things done because C is such a powerful, dominant and supple language 5. Its use quickly spread beyond Bell Labs in the late 70’s because of its long list of strong features. Basics In C – Programming Below are few commands and syntax used in C programming to write a simple C program. Let’s see all the sections of a simple C program line by line. C Basic commands Explanation #include <stdio.h> This is a pre-processor command that includes standard input output header file(stdio.h) from the C library before
  • 4. compiling a C program int main() This is the main function from where execution of any C program begins. { This indicates the beginning of the main function. /*_some_comments_*/ whatever is given inside the command “/* */” in any C program, won’t be considered for compilation and execution. printf(“Hello_World!“); printf command prints the output onto the screen. getch(); This command waits for any character input from keyboard. return 0; This command terminates C program (main function) and returns 0. } This indicates the end of the main function Printf() and scanf() in C : The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file). printf() function  The printf() function is used for output. It prints the given statement to the console.  The syntax of printf() function is given below: printf("format string",argument_list);  The format string can be %d (integer), %c (character), %s (string), %f (float) etc. scanf() function  The scanf() function is used for input. It reads the input data from the console.  The syntax of scanf() function is given below:  scanf("format string",argument_list);
  • 5. Variables in C: A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times. It is a way to represent memory location through symbol so that it can be easily identified. The example of declaring variable is given below: int a; float b; char c; Here, a, b, c are variables and int,float,char are data types. We can also provide values while declaring the variables as given below: int a=10,b=20;//declaring 2 variable of integer type float f=20.8; char c='A'; Rules for defining variables o A variable can have alphabets, digits and underscore. o A variable name can start with alphabet and underscore only. It can't start with digit. o No white space is allowed within variable name. o A variable name must not be any reserved word or keyword e.g. int, float etc. Types of Variables in C There are many types of variables in c: 1. local variable 2. global variable 3. static variable 4. automatic variable 5. external variable Local Variable A variable that is declared inside the function or block is called local variable.
  • 6. It must be declared at the start of the block. You must have to initialize the local variable before it is used. Global Variable A variable that is declared outside the function or block is called global variable. Any function can change the value of the global variable. Itis available to all the functions. It must be declared at the start of the block. Static Variable A variable that is declared with static keyword is called static variable. It retains its value between multiple function calls. If you call this function many times, local variable will print the same value for each function call e.g, 11,11,11 and so on. But static variable will print the incremented value in each function call e.g. 11, 12, 13 and so on. Automatic Variable All variables in C that is declared inside the block, are automatic variables by default. By we can explicitly declare automatic variable using auto keyword. External Variable We can share a variable in multiple C source files by using external variable. To declare a external variable, you need to use extern keyword.
  • 7.
  • 8. Data Types in C: A data type specifies the type of data that a variable can store such as integer, floating, character etc. There are 4 types of data types in C language. Types Data Types Basic Data Type int, char, float, double Derived Data Type array, pointer, structure, union Enumeration Data Type enum Void Data Type void Basic Data Types The basic data types are integer-based and floating-point based. C language supports bothsigned and unsigned literals. The memory size of basic data types may change according to 32 or 64 bit operating system. Let's see the basic data types. Its size is given according to 32 bit architecture.
  • 9. Data Types Memory Size Range char 1 byte −128 to 127 signed char 1 byte −128 to 127 unsigned char 1 byte 0 to 255 short 2 byte −32,768 to 32,767 signed short 2 byte −32,768 to 32,767 unsigned short 2 byte 0 to 65,535 int 2 byte −32,768 to 32,767 signed int 2 byte −32,768 to 32,767 unsigned int 2 byte 0 to 65,535 short int 2 byte −32,768 to 32,767 signed short int 2 byte −32,768 to 32,767 unsigned short int 2 byte 0 to 65,535 long int 4 byte -2,147,483,648 to 2,147,483,647 signed long int 4 byte -2,147,483,648 to 2,147,483,647 unsigned long int 4 byte 0 to 4,294,967,295 float 4 byte
  • 10. double 8 byte long double 10 byte Keywords in C: A keyword is a reserved word. You cannot use it as a variable name, constant name etc. There are only 32 reserved words (keywords) in C language. C Operators: An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise etc. There are following types of operators to perform different types of operations in C language. o Arithmetic Operators o Relational Operators o Shift Operators o Logical Operators o Bitwise Operators o Ternary or Conditional Operators o Assignment Operator o Misc Operator C Control Statements Control statements is given below: C if else Statement The if statement in C language is used to perform operation on the basis of condition. By using if-else statement, you can perform operation either condition is true or false. There are many ways to use if statement in C language:
  • 11. o If statement o If-else statement o If else-if ladder o Nested if If Statement The single if statement in C language is used to execute the code if condition is true. The syntax of if statement is given below: 1. if(expression){ 2. //code to be executed 3. } If-else Statement The if-else statement in C language is used to execute the code if condition is true or false. The syntax of if-else statement is given below: 1. if(expression){ 2. //code to be executed if condition is true 3. }else{ 4. //code to be executed if condition is false 5. } If else-if ladder Statement The if else-if statement is used to execute one code from multiple conditions. The syntax of if else-if statement is given below: 1. if(condition1){ 2. //code to be executed if condition1 is true 3. }else if(condition2){ 4. //code to be executed if condition2 is true 5. } 6. else if(condition3){ 7. //code to be executed if condition3 is true 8. } 9. ... 10. else{ 11. //code to be executed if all the conditions are false 12. }
  • 12. C Switch Statement The switch statement in C language is used to execute the code from multiple conditions. It is like if else-if ladder statement. C Loops The loops in C language are used to execute a block of code or a part of the program several times. In other words, it iterates a code or group of code many times. Advantage of loops in C 1) It saves code. 2) It helps to traverse the elements of array Types of C Loops There are three types of loops in C language that is given below: 1. do while 2. while 3. for do-while loop in C It iterates the code until condition is false. Here, condition is given after the code. So at least once, code is executed whether condition is true or false. while loop in C Like do while, it iterates the code until condition is false. Here, condition is given before the code. So code may be executed 0 or more times. It is better if number of iteration is not known by the user. The syntax of while loop in c language is given below: 1. while(condition){
  • 13. 2. //code to be executed 3. } for loop in C Like while, it iterates the code until condition is false. Here, initialization, condition and increment/decrement is given before the code. So code may be executed 0 or more times. It is good if number of iteration is known by the user. The syntax of for loop in c language is given below: 1. for(initialization;condition;incr/decr){ 2. //code to be executed 3. } do while loop in C To execute a part of program or code several times, we can use do-while loop of C language. The code given between the do and while block will be executed until condition is true. In do while loop, statement is given before the condition, so statement or code will be executed at lease one time. In other words, we can say it is executed 1 or more times. It is better if you have to execute the code at least once. do while loop syntax The syntax of C language do-while loop is given below: 1. do{ 2. //code to be executed 3. }while(condition);
  • 14. C Functions: The function in C language is also known as procedure or subroutine in other programming languages. To perform any task, we can create function. A function can be called many times. It provides modularity and code reusability. Types of Functions There are two types of functions in C programming: 1. Library Functions: are the functions which are declared in the C header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc. 2. User-defined functions: are the functions which are created by the C programmer, so that he/she can use it many times. It reduces complexity of a big program and optimizes the code. Call by value and call by reference in C There are two ways to pass value or data to function in C language: call by value and call by reference. Original value is not modified in call by value but it is modified in call by reference. Call by value in C In call by value, original value is not modified. In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only. It will not change the value of variable inside the caller method such as main(). Call by reference in C In call by reference, original value is modified because we pass reference (address). Here, address of the value is passed in the function, so actual and formal arguments shares the same address space. Hence, value changed inside the function, is reflected inside as well as outside the function. Recursion in C
  • 15. When function is called within the same function, it is known as recursion in C. The function which calls the same function, is known as recursive function. A function that calls itself, and doesn't perform any task after function call, is know as tail recursion. In tail recursion, we generally call the same function with return statement. Storage Classes in C Storage classes are used to define scope and life time of a variable. There are four storage classes in C programming. o auto o extern o static o register C Array: Array in C language is a collection or group of elements (data). All the elements of c array are homogeneous (similar). It has contiguous memory location. Advantage of C Array 1) Code Optimization: Less code to the access the data. 2) Easy to traverse data: By using the for loop, we can retrieve the elements of an array easily. 3) Easy to sort data: To sort the elements of array, we need a few lines of code only. 4) Random Access: We can access any element randomly using the array. Declaration of C Array We can declare an array in the c language in the following way. data_type array_name[array_size]; Two Dimensional Array in C
  • 16. The two dimensional array in C language is represented in the form of rows and columns, also known as matrix. It is also known as array of arrays or list of arrays. The two dimensional, three dimensional or other dimensional arrays are also known as multidimensional arrays. Declaration of two dimensional Array in C We can declare an array in the c language in the following way. 1. data_type array_name[size1][size2]; Passing Array to Function in C To reuse the array operation, we can create functions that receives array as argument. To pass array in function, we need to write the array name only in the function call. C Pointers: The pointer in C language is a variable, it is also known as locator or indicator that points to an address of a value. Declaring a pointer The pointer in c language can be declared using * (asterisk symbol). int *a;//pointer to int char *c;//pointer to char NULL Pointer A pointer that is not assigned any value but NULL is known as NULL pointer. If you don't have any address to be specified in the pointer at the time of declaration, you can assign NULL value. It will a better approach. int *p=NULL; In most the libraries, the value of pointer is 0 (zero).
  • 17. C Pointer to Pointer In C pointer to pointer concept, a pointer refers to the address of another pointer. In c language, a pointer can point to the address of another pointer which points to the address of a value. Let's understand it by the diagram given below: Let's see the syntax of pointer to pointer. int **p2; Dynamic memory allocation in C The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime. Dynamic memory allocation in c language is possible by 4 functions of stdlib.h header file. 1. malloc() 2. calloc() 3. realloc() 4. free() Before learning above functions, let's understand the difference between static memory allocation and dynamic memory allocation. static memory allocation dynamic memory allocation memory is allocated at compile time. memory is allocated at run time. memory can't be increased while executing program. memory can be increased while exec used in array. used in linked list. Now let's have a quick look at the methods used for dynamic memory allocation.
  • 18. malloc() allocates single block of requested memory. calloc() allocates multiple block of requested memory. realloc() reallocates the memory occupied by malloc() or calloc() functions. free() frees the dynamically allocated memory. malloc() function in C The malloc() function allocates single block of requested memory. It doesn't initialize memory at execution time, so it has garbage value initially. It returns NULL if memory is not sufficient. The syntax of malloc() function is given below: ptr=(cast-type*)malloc(byte-size) calloc() function in C The calloc() function allocates multiple block of requested memory. It initially initialize all bytes to zero. It returns NULL if memory is not sufficient. The syntax of calloc() function is given below: ptr=(cast-type*)calloc(number, byte-size) realloc() function in C If memory is not sufficient for malloc() or calloc(), you can reallocate the memory by realloc() function. In short, it changes the memory size. Let's see the syntax of realloc() function. 1. ptr=realloc(ptr, new-size)
  • 19. free() function in C The memory occupied by malloc() or calloc() functions must be released by calling free() function. Otherwise, it will consume memory until program exit. Let's see the syntax of free() function. free(ptr) C Strings: String in C language is an array of characters that is terminated by 0 (null character). There are two ways to declare string in c language. 1. By char array 2. By string literal C gets() and puts() functions The gets() function reads string from user and puts() function prints the string. Both functions are defined in <stdio.h> header file. C Structure Union: Structure in c language is a user defined datatype that allows you to hold different type of elements. Each element of a structure is called a member. It works like a template in C++ and class in Java. You can have different type of elements in it. Defining structure The struct keyword is used to define structure. Let's see the syntax to define structure in c. 1. struct structure_name 2. { 3. data_type member1; 4. data_type member2; 5. data_type memeberN; 6. };
  • 20. Array of Structures in C There can be array of structures in C programming to store many information of different data types. The array of structures is also known as collection of structures. Nested Structure in C Nested structure in c language can have another structure as a member. There are two ways to define nested structure in c language: 1. By separate structure 2. By Embedded structure 1) Separate structure We can create 2 structures, but dependent structure should be used inside the main structure as a member. Let's see the code of nested structure. 2) Embedded structure We can define structure within the structure also. It requires less code than previous way. But it can't be used in many structures. C Union Like structure, Union in c language is a user defined datatype that is used to hold different type of elements. But it doesn't occupy sum of all members size. It occupies the memory of largest member only. It shares memory of largest member.
  • 21. Advantage of union over structure It occupies less memory because it occupies the memory of largest member only. Disadvantage of union over structure It can store data in one member only. Defining union The union keyword is used to define union. Let's see the syntax to define union in c. 1. union union_name 2. { 3. data_type member1; 4. data_type member2; 5. . 6. . 7. data_type memeberN; 8. }; File Handling in C: File Handling in c language is used to open, read, write, search or close file. It is used for permanent storage. Advantage of File It will contain the data even after program exit. Normally we use variable or array to store data, but data is lost after program exit. Variables and arrays are non-permanent storage medium whereas file is permanent storage medium. Functions for file handling There are many functions in C library to open, read, write, search and close file. A list of file functions are given below:
  • 22. No. Function Description 1 fopen() opens new or existing file 2 fprintf() write data into file 3 fscanf() reads data from file 4 fputc() writes a character into file 5 fgetc() reads a character from file 6 fclose() closes the file 7 fseek() sets the file pointer to given position 8 fputw() writes an integer to file 9 fgetw() reads an integer from file 10 ftell() returns current position 11 rewind() sets the file pointer to the beginning of the file THANK YOU