SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
BASICS OF “C” PROGRAMMING
By
R.Sivagami, Assistant Professor
Department of Computer Science and Applications
D.K.M College for women(Autonomous), Vellore-1.
TOPICS COVERED
 Structure of C program
 Compiling A C program
 What goes inside the compilation process?
STRUCTURE OF C PROGRAM:
 A C Program is divided into six sections
1) Documentation
2) Link
3) Definition
4 Global Declaration
5) Main()
6) Sub programs
DOCUMENTATION
* Consists of description of the program such as the name of the
program, creation date and time of the program.
* It is specified at the start of the program.
* Any thing written as comments will be treated as documentation
of the program and this will not interfere with the given code.
* In a C Program, Single-line comments can be written using two
forward slashes i.e., //
* Multi-line comments can be represented using /* */
Example
/* description, name of the program, programmer name, date, time
etc. */
LINK SECTION
 All header files are included in this section
 A header file is a file that consists of C declarations that can be
used between different files.
 It helps us in using other’s code in our files.
 A copy of these header files is inserted into the code before
compilation
Example
#include<stdio.h>
#include<math.h>
DEFINITION
* A Preprocessor directive in C is any statement that begins with the “#” symbol.
* The #define is a preprocessor compiler directive used to create constants.
* They basically allows the macro definition, which allows the use of constants in
our code
* Whenever this name is encountered by the compiler, it is replaced by the actual
piece of defined code.
* #define statements does not ends with a semicolon
Example
#define long long ll
GLOBAL DECLARATION
 This section include all global variables, function
declarations, and static variables
 Variables and functions which are declared in this scope can
be used anywhere in the program.
Example
int num = 18;
MAIN() FUNCTION
 For every C Program, the execution starts from the main() function.
 It is mandatory to include a main() function in every C Program
 Operations like declaration and execution are performed inside the curly braces
of the main program.
 The return type of the main() function can be int as well as void too.
 Void() main tells the compiler that the program will not return any value.
 The int main() tells the compiler that the program will return an integer value.
Example
void main()
Or
int main()
SUB PROGRAMS
 Includes all user-defined functions(functions the user defined).
 They can contain the in built functions and the function
definitions declared in the Global Declaration section.
 The control of the program is shifted to the called function
whenever they are called from the main or outside the main()
function.
 These are specified as per the requirements of the programmer.
Example
int sum(int x, int y)
{
return x+y;
}
//*****
*PROGRAM TO FIND SUM OF THE GIVEN NUMBERS.
*/ //Documentation
#include<stdio.h> //Link
#define X 20 // Definition
int sum(int y); // Global declaration
int main(void) // Main function
{
int y=55;
printf(“sum: %d”,sum(y));
return 0;
}
int sum(int y) //Sub program
{
return y+x;
}
O/P
Sum:75
STEPS INVOLVED IN THE COMPILATION AND
EXECUTION OF A C PROGRAM
 Program Creation
 Compilation of the program
 Execution of the program
 The output of the program
COMPILING A C PROGRAM:
The C program goes through the following phases during
compilation:
HOW DO WE COMPILE AND RUN A C PROGRAM?
Step 1: Creating a C Source File
Step 2: Compiling
Step 3: Executing the program
WHAT GOES INSIDE THE COMPILATION PROCESS?
A compiler converts a C program into an executable. There are
four phases for a C program to become an executable:
 Pre-processing
 Compilation
 Assembly
 Linking
The following screenshot shows all generated intermediate files.
1. PRE-PROCESSING
This is the first phase through which source code is passed.
This phase includes:
 Removal of Comments
 Expansion of Macros
 Expansion of the included files.
 Conditional compilation
2. COMPILING
The next step is to compile filename.i and produce an; intermediate compiled
output file filename.s. This file is in assembly-level instructions.
3. ASSEMBLING
 In this phase the filename.s is taken as input and turned
into filename.o by the assembler. This file contains machine-level
instructions.
4. LINKING
 This is the final phase in which all the linking of function calls with
their definitions is done.
 Linker knows where all these functions are implemented. Linker does
some extra work also, it adds some extra code to our program which is
required when the program starts and ends.
 For example, there is a code that is required for setting up the
environment like passing command line arguments.
 This task can be easily verified by using $size filename.o and $size
filename. Through these commands, we know how the output file
increases from an object file to an executable file.
 This is because of the extra code that Linker adds to our program.
THANK YOU

Weitere ähnliche Inhalte

Ähnlich wie C PROGRAMMING p-2.pdf

C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languageGautamGupta136
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Nuzhat Memon
 
C programming course material
C programming course materialC programming course material
C programming course materialRanjitha Murthy
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
Overview of c++
Overview of c++Overview of c++
Overview of c++geeeeeet
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of ckinish kumar
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 

Ähnlich wie C PROGRAMMING p-2.pdf (20)

chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C language
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Book management system
Book management systemBook management system
Book management system
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
 
C tutorials
C tutorialsC tutorials
C tutorials
 
C programming course material
C programming course materialC programming course material
C programming course material
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
C structure
C structureC structure
C structure
 
Overview of c
Overview of cOverview of c
Overview of c
 

Kürzlich hochgeladen

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
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
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
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
 
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
 

Kürzlich hochgeladen (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
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
 
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Ữ Â...
 

C PROGRAMMING p-2.pdf

  • 1. BASICS OF “C” PROGRAMMING By R.Sivagami, Assistant Professor Department of Computer Science and Applications D.K.M College for women(Autonomous), Vellore-1.
  • 2. TOPICS COVERED  Structure of C program  Compiling A C program  What goes inside the compilation process?
  • 3. STRUCTURE OF C PROGRAM:  A C Program is divided into six sections 1) Documentation 2) Link 3) Definition 4 Global Declaration 5) Main() 6) Sub programs
  • 4. DOCUMENTATION * Consists of description of the program such as the name of the program, creation date and time of the program. * It is specified at the start of the program. * Any thing written as comments will be treated as documentation of the program and this will not interfere with the given code. * In a C Program, Single-line comments can be written using two forward slashes i.e., // * Multi-line comments can be represented using /* */ Example /* description, name of the program, programmer name, date, time etc. */
  • 5. LINK SECTION  All header files are included in this section  A header file is a file that consists of C declarations that can be used between different files.  It helps us in using other’s code in our files.  A copy of these header files is inserted into the code before compilation Example #include<stdio.h> #include<math.h>
  • 6. DEFINITION * A Preprocessor directive in C is any statement that begins with the “#” symbol. * The #define is a preprocessor compiler directive used to create constants. * They basically allows the macro definition, which allows the use of constants in our code * Whenever this name is encountered by the compiler, it is replaced by the actual piece of defined code. * #define statements does not ends with a semicolon Example #define long long ll
  • 7. GLOBAL DECLARATION  This section include all global variables, function declarations, and static variables  Variables and functions which are declared in this scope can be used anywhere in the program. Example int num = 18;
  • 8. MAIN() FUNCTION  For every C Program, the execution starts from the main() function.  It is mandatory to include a main() function in every C Program  Operations like declaration and execution are performed inside the curly braces of the main program.  The return type of the main() function can be int as well as void too.  Void() main tells the compiler that the program will not return any value.  The int main() tells the compiler that the program will return an integer value. Example void main() Or int main()
  • 9. SUB PROGRAMS  Includes all user-defined functions(functions the user defined).  They can contain the in built functions and the function definitions declared in the Global Declaration section.  The control of the program is shifted to the called function whenever they are called from the main or outside the main() function.  These are specified as per the requirements of the programmer. Example int sum(int x, int y) { return x+y; }
  • 10. //***** *PROGRAM TO FIND SUM OF THE GIVEN NUMBERS. */ //Documentation #include<stdio.h> //Link #define X 20 // Definition int sum(int y); // Global declaration int main(void) // Main function { int y=55; printf(“sum: %d”,sum(y)); return 0; } int sum(int y) //Sub program { return y+x; } O/P Sum:75
  • 11. STEPS INVOLVED IN THE COMPILATION AND EXECUTION OF A C PROGRAM  Program Creation  Compilation of the program  Execution of the program  The output of the program
  • 12. COMPILING A C PROGRAM: The C program goes through the following phases during compilation:
  • 13. HOW DO WE COMPILE AND RUN A C PROGRAM? Step 1: Creating a C Source File Step 2: Compiling Step 3: Executing the program
  • 14. WHAT GOES INSIDE THE COMPILATION PROCESS? A compiler converts a C program into an executable. There are four phases for a C program to become an executable:  Pre-processing  Compilation  Assembly  Linking
  • 15. The following screenshot shows all generated intermediate files.
  • 16. 1. PRE-PROCESSING This is the first phase through which source code is passed. This phase includes:  Removal of Comments  Expansion of Macros  Expansion of the included files.  Conditional compilation
  • 17. 2. COMPILING The next step is to compile filename.i and produce an; intermediate compiled output file filename.s. This file is in assembly-level instructions.
  • 18. 3. ASSEMBLING  In this phase the filename.s is taken as input and turned into filename.o by the assembler. This file contains machine-level instructions.
  • 19. 4. LINKING  This is the final phase in which all the linking of function calls with their definitions is done.  Linker knows where all these functions are implemented. Linker does some extra work also, it adds some extra code to our program which is required when the program starts and ends.  For example, there is a code that is required for setting up the environment like passing command line arguments.  This task can be easily verified by using $size filename.o and $size filename. Through these commands, we know how the output file increases from an object file to an executable file.  This is because of the extra code that Linker adds to our program.