SlideShare a Scribd company logo
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

More Related Content

Similar to 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
 

Similar to 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
 

Recently uploaded

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativePeter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfSpecial education needs
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)rosedainty
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...Jisc
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...EugeneSaldivar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasGeoBlogs
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptxJosvitaDsouza2
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...AzmatAli747758
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 

Recently uploaded (20)

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

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.