SlideShare une entreprise Scribd logo
1  sur  32
C Program Structure
REHAN IJAZ
By
ProgrammingFundamentals
 The main function serves as the starting point for program execution.
 It usually executes statements and controls program execution by
directing the calls to other functions in the program.
 A program usually stops executing at the end of main, although it can
terminate at other points in the program for a variety of reasons.
 At times, perhaps when a certain error is detected, you may want to force
the termination of a program. To do so, use the exit function.
 All C language programs must have a main() function.
 It's the core of every program. It's required.
 The main() function doesn't really have to do anything other than be
present inside your C source code.
 Eventually, it contains instructions that tell the computer to carry out
whatever task your program is designed to do. But it's not officially
required to do anything.
 When the operating system runs a program in C, it passes control of the
computer over to that program.
 In the case of a C language program, it's the main() function that the
operating system is looking for to pass the control.
 At a minimum, the main() function looks like this:
main()
{
}
 Like all C language functions,
 first comes the function's name, main,
 then comes a set of parentheses, and
 finally comes a set of braces, also called curly braces.
Command Explanation
1 #include <stdio.h> This is a preprocessor command that includes standard
input output header file(stdio.h) from the C library before
compiling a C program
2 int main() This is the main function from where execution of any C
program begins.
3 { This indicates the beginning of the main function.
4 printf(“Hello_World! “); printf command prints the output onto the screen.
5 getch(); This command waits for any character input from
keyboard.
6 return 0; This command terminates C program (main function) and
returns 0.
7 } This indicates the end of the main function.
 A statement is a command given to the computer that instructs the
computer to take a specific action, such as display to the screen, or
collect input.
 A computer program is made up of a series of statements.
 An assignment statement assigns a value to a variable. A printf()
statement writes desired text e.g.
 printf(“Hello_World! “);
 Int Stdregno, age;
 Compound Statement also called a "block“is the way C groups multiple
statements into a single statement with the help of braces (i.e. { and }).
 The body of a function is also a compound statement by rule.
#include <stdio.h>
void main()
{
printf("Hello, world!n");
getch();
}
 A comment is a note to yourself (or others) that you put into your source
code.
 Comments provide clarity to the C source code allowing yourself and
others to better understand what the code was intended to accomplish
and greatly helping in debugging the code.
 All comments are ignored by the compiler they are not executed as part
of the program.
 Comments are especially important in large projects containing hundreds
or thousands of lines of source code or in projects in which many
contributors are working on the source code.
 Comments are typically added directly above the related C source code.
 Adding source code comments to your C source code is a highly
recommended practice.
 Types
(i) Single line Comment
// comment goes here
(ii) Block Comment
/* comment goes here
more comment goes here */
 When we say Input, it means to feed some data into a program. An input
can be given in the form of a file or from the command line. C
programming provides a set of built-in functions to read the given input
and feed it to the program as per requirement.
 When we say Output, it means to display some data on screen, printer, or
in any file. C programming provides a set of built-in functions to output
the data on the computer screen as well as to save it in text or binary
files.
 INPUT: When we say Input, it means to feed some data into a program.
An input can be given in the form of a file or from the command line. C
programming provides a set of built-in functions to read the given input
and feed it to the program as per requirement.
 OUTPUT: When we say Output, it means to display some data on screen,
printer, or in any file. C programming provides a set of built-in functions
to output the data on the computer screen as well as to save it in text or
binary files.
printf()
 function writes the output to the standard output stream and produces
the output according to the format provided.
 The format can be a simple constant string, but you can specify %s, %d,
%c, %f, etc., to print or read strings, integer, character or float
respectively.
scanf()
 function reads the input from the standard input stream and scans that
input according to the format provided.
Example
#include <stdio.h>
int main( )
{
char str[100];
int i;
printf( "Enter values :");
scanf("%s %d", str, &i);
printf( "nYou entered: %s %d ", str, i);
return 0;
}
Enter a value : seven 7
You entered: seven 7
 C pre processor refers to a separate program which will be invoked by the
compiler as first part of translation.
 Before a C program is compiled in a compiler, source code is processed by a
program called preprocessor. This process is called preprocessing.
 Commands used in preprocessor are called preprocessor directives and they
begin with “#” symbol.
Source Code Preprocessor Compiler Object Code
 The preprocessor provides the ability for the inclusion of header files.
 Preprocessor directives are lines included in the code of programs preceded
by a hash sign (#).
 These lines are not program statements but directives for the preprocessor.
 The preprocessor examines the code before actual compilation of code
begins and resolves all these directives before any code is actually
generated by regular statements.
 No semicolon (;) is expected at the end of a preprocessor directive.
 Preprocessor directive can be extended by a backslash ().
Few examples of preprocessor directives
 #include<stdio.h>
 #include<conio.h>
 #include<math.h>
etc.
S.no Preprocessor Syntax Description
1
Header file
inclusion
#include
<file_name>
The source code of the file “file_name” is included in the
main program at the specified place
2 Macro #define
This macro defines constant value and can be any of the basic
data types.
3
Conditional
compilation
#ifdef,
#endif, #if,
#else,
#ifndef
Set of commands are included or excluded in source program
before compilation with respect to the condition
4
Other
directives
#undef,
#pragma
#undef is used to undefine a defined macro variable.
#Pragma is used to call a function before and after main
function in a C program
 #include pre processor directive is used to include header files in the
program.
 If header file name is enclosed within angle brackets (), then compiler
search this file only within its standard include directory.
 Similarly, if header file name is enclosed within double quotes (“ ”) then
compiler will search this file within and out side of its standard path.
1. Header file inclusion (#include)
#include <stdio.h>
void main()
{
printf("Hello, world!n");
getch();
}
1. Header file inclusion (#include)
Example
 In C/C++ programming language, Define directive is used for multi
functions such as to define a symbol, to define a name constant or to
define macros (short and fast processed code)
 (a) To define a symbol,
 (b)To define name and constants
 (c) To define macros
2. Macro - Define Directive (#define)
(a) To define a symbol,
 In the first statement, NULL is a symbol which would be replaced
with 0 in a program. Similarly, the symbol PLUS can be replaced with
+. So following both statements will be work in the same way.
2. Macro - Define Directive (#define)
C=A PLUS B;
it will work same as C=A+B;
#define NUL 0
#define PLUS +
(b) To define name and constants
 #define preprocessor can help to define a named constant. Such as
2. Macro - Define Directive (#define)
#define INTEGER 5
#define CHARACTER A
(c) To define macro
 In C/C++ programming language, a macro is defined as a segment of text
and it is very useful due to its readability or compact factors. Some
examples of macros are
2. Macro - Define Directive (#define)
#define pi 22.0/7
#define Area(r) 3.14*r*r
 The first macro is very simple and its name can be used in any expression such as
A= pi* 5. Similarly, second macro has a parameter r and it calculate the area.
 If a macro is defined at more than one line then you need to place  at the end of
each line except last line.  Symbol is used for continuation from next line.
2. Macro - Define Directive (#define) (c) To define macro
value of height : 100
value of number : 3.140000
value of letter : A
value of letter_sequence : ABC
value of backslash_char : ?
#include <stdio.h>
#define height 100
#define number 3.14
#define letter 'A'
#define letter_sequence "ABC"
#define backslash_char '?'
void main()
{
printf("value of height : %d ", height );
printf("value of number : %f ", number );
printf("value of letter : %c ", letter );
printf("value of letter_sequence : %s ", letter_sequence);
printf("value of backslash_char : %c ", backslash_char);
}
Output:
 In this type of preprocessor, #ifdef directive is used to check the
existence of defined macros, constant name or symbol. For example,
when we write following statement
 The work of #ifndef directive is same as of #ifdef but there is slight
difference. For #ifdef directive, if a symbol or named constant or
macro has been undefined by using #undef then #ifdef will return
false valu, but #ifndef will return true value for such case.
3. Conditional Compilation(#ifdef, #ifndef, #endif)
3. Conditional Compilation(#ifdef, #ifndef, #endif)
Khalid is defined. So, this line will be added in this C file
#include <stdio.h>
#define Khalid 10
int main()
{
#ifdef Khalid
printf("Khalid is defined. So, this line will be added in this C file");
#else
printf("Khalid is not defined");
#endif
return 0;
}
Output:
 #undef preprocessor directive is used to undefined a macro, named
constant or any symbol which has been defined earlier.
 Unlike #include and # define directives, #undef directive can be used
everywhere in a program but after the #define preprocessor.
#undef pi
#undef PLUS
4. Undefine Directives (#undef)
Programming Fundamentals lecture 5

Contenu connexe

Tendances

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
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of Ceducationfront
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Rumman Ansari
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143alish sha
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.NabeelaNousheen
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 

Tendances (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
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Lesson 7 io statements
Lesson 7 io statementsLesson 7 io statements
Lesson 7 io statements
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
C programming language
C programming languageC programming language
C programming language
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
C programming
C programmingC programming
C programming
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C Programming
C ProgrammingC Programming
C Programming
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 

En vedette

Chicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATIONChicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATIONAura Gondayao
 
Herbs that stimulate hair regrowth
Herbs that stimulate hair regrowthHerbs that stimulate hair regrowth
Herbs that stimulate hair regrowthzaracollins42
 
Diabeties control through herbs By Allah Dad Khan
Diabeties control through herbs By Allah Dad KhanDiabeties control through herbs By Allah Dad Khan
Diabeties control through herbs By Allah Dad KhanMr.Allah Dad Khan
 
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar LevelsNaturogain
 
pineapple and peppermint
pineapple and peppermint pineapple and peppermint
pineapple and peppermint Shubham Nahar
 
importance of Communication in business
importance of Communication in businessimportance of Communication in business
importance of Communication in businessREHAN IJAZ
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7REHAN IJAZ
 
Career development interviews
Career development interviewsCareer development interviews
Career development interviewsREHAN IJAZ
 
Trevel presentation
Trevel presentationTrevel presentation
Trevel presentationindra Kishor
 
How to make presentation effective assignment
How to make presentation effective assignmentHow to make presentation effective assignment
How to make presentation effective assignmentREHAN IJAZ
 
Programming Fundamentals lecture 3
Programming Fundamentals lecture 3Programming Fundamentals lecture 3
Programming Fundamentals lecture 3REHAN IJAZ
 

En vedette (12)

Chicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATIONChicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATION
 
Albert P. Camungao cv
Albert P. Camungao   cvAlbert P. Camungao   cv
Albert P. Camungao cv
 
Herbs that stimulate hair regrowth
Herbs that stimulate hair regrowthHerbs that stimulate hair regrowth
Herbs that stimulate hair regrowth
 
Diabeties control through herbs By Allah Dad Khan
Diabeties control through herbs By Allah Dad KhanDiabeties control through herbs By Allah Dad Khan
Diabeties control through herbs By Allah Dad Khan
 
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels
10 Anti-Diabetic Herbs to Control Diabetes or High Blood Sugar Levels
 
pineapple and peppermint
pineapple and peppermint pineapple and peppermint
pineapple and peppermint
 
importance of Communication in business
importance of Communication in businessimportance of Communication in business
importance of Communication in business
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
 
Career development interviews
Career development interviewsCareer development interviews
Career development interviews
 
Trevel presentation
Trevel presentationTrevel presentation
Trevel presentation
 
How to make presentation effective assignment
How to make presentation effective assignmentHow to make presentation effective assignment
How to make presentation effective assignment
 
Programming Fundamentals lecture 3
Programming Fundamentals lecture 3Programming Fundamentals lecture 3
Programming Fundamentals lecture 3
 

Similaire à Programming Fundamentals lecture 5

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
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docxtarifarmarie
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.pptatulchaudhary821
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg PatelTechNGyan
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramDeepak Singh
 

Similaire à Programming Fundamentals lecture 5 (20)

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
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Chapter3
Chapter3Chapter3
Chapter3
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
C programming
C programmingC programming
C programming
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
 
C structure
C structureC structure
C structure
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
 

Plus de REHAN IJAZ

Project code for Project on Student information management system
Project code for Project on Student information management systemProject code for Project on Student information management system
Project code for Project on Student information management systemREHAN IJAZ
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8REHAN IJAZ
 
Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1REHAN IJAZ
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6REHAN IJAZ
 
Programming Fundamentals lecture 4
Programming Fundamentals lecture 4Programming Fundamentals lecture 4
Programming Fundamentals lecture 4REHAN IJAZ
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2REHAN IJAZ
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1REHAN IJAZ
 
Porposal on Student information management system
Porposal on Student information management systemPorposal on Student information management system
Porposal on Student information management systemREHAN IJAZ
 
Project on Student information management system
Project on Student information management systemProject on Student information management system
Project on Student information management systemREHAN IJAZ
 

Plus de REHAN IJAZ (9)

Project code for Project on Student information management system
Project code for Project on Student information management systemProject code for Project on Student information management system
Project code for Project on Student information management system
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
 
Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
Programming Fundamentals lecture 4
Programming Fundamentals lecture 4Programming Fundamentals lecture 4
Programming Fundamentals lecture 4
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Porposal on Student information management system
Porposal on Student information management systemPorposal on Student information management system
Porposal on Student information management system
 
Project on Student information management system
Project on Student information management systemProject on Student information management system
Project on Student information management system
 

Dernier

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 

Dernier (20)

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 

Programming Fundamentals lecture 5

  • 1. C Program Structure REHAN IJAZ By ProgrammingFundamentals
  • 2.  The main function serves as the starting point for program execution.  It usually executes statements and controls program execution by directing the calls to other functions in the program.  A program usually stops executing at the end of main, although it can terminate at other points in the program for a variety of reasons.  At times, perhaps when a certain error is detected, you may want to force the termination of a program. To do so, use the exit function.
  • 3.  All C language programs must have a main() function.  It's the core of every program. It's required.  The main() function doesn't really have to do anything other than be present inside your C source code.  Eventually, it contains instructions that tell the computer to carry out whatever task your program is designed to do. But it's not officially required to do anything.
  • 4.  When the operating system runs a program in C, it passes control of the computer over to that program.  In the case of a C language program, it's the main() function that the operating system is looking for to pass the control.  At a minimum, the main() function looks like this: main() { }
  • 5.  Like all C language functions,  first comes the function's name, main,  then comes a set of parentheses, and  finally comes a set of braces, also called curly braces.
  • 6. Command Explanation 1 #include <stdio.h> This is a preprocessor command that includes standard input output header file(stdio.h) from the C library before compiling a C program 2 int main() This is the main function from where execution of any C program begins. 3 { This indicates the beginning of the main function. 4 printf(“Hello_World! “); printf command prints the output onto the screen. 5 getch(); This command waits for any character input from keyboard. 6 return 0; This command terminates C program (main function) and returns 0. 7 } This indicates the end of the main function.
  • 7.  A statement is a command given to the computer that instructs the computer to take a specific action, such as display to the screen, or collect input.  A computer program is made up of a series of statements.  An assignment statement assigns a value to a variable. A printf() statement writes desired text e.g.  printf(“Hello_World! “);  Int Stdregno, age;
  • 8.  Compound Statement also called a "block“is the way C groups multiple statements into a single statement with the help of braces (i.e. { and }).  The body of a function is also a compound statement by rule. #include <stdio.h> void main() { printf("Hello, world!n"); getch(); }
  • 9.  A comment is a note to yourself (or others) that you put into your source code.  Comments provide clarity to the C source code allowing yourself and others to better understand what the code was intended to accomplish and greatly helping in debugging the code.  All comments are ignored by the compiler they are not executed as part of the program.
  • 10.  Comments are especially important in large projects containing hundreds or thousands of lines of source code or in projects in which many contributors are working on the source code.  Comments are typically added directly above the related C source code.  Adding source code comments to your C source code is a highly recommended practice.
  • 11.  Types (i) Single line Comment // comment goes here (ii) Block Comment /* comment goes here more comment goes here */
  • 12.  When we say Input, it means to feed some data into a program. An input can be given in the form of a file or from the command line. C programming provides a set of built-in functions to read the given input and feed it to the program as per requirement.  When we say Output, it means to display some data on screen, printer, or in any file. C programming provides a set of built-in functions to output the data on the computer screen as well as to save it in text or binary files.
  • 13.  INPUT: When we say Input, it means to feed some data into a program. An input can be given in the form of a file or from the command line. C programming provides a set of built-in functions to read the given input and feed it to the program as per requirement.  OUTPUT: When we say Output, it means to display some data on screen, printer, or in any file. C programming provides a set of built-in functions to output the data on the computer screen as well as to save it in text or binary files.
  • 14. printf()  function writes the output to the standard output stream and produces the output according to the format provided.  The format can be a simple constant string, but you can specify %s, %d, %c, %f, etc., to print or read strings, integer, character or float respectively.
  • 15. scanf()  function reads the input from the standard input stream and scans that input according to the format provided.
  • 16. Example #include <stdio.h> int main( ) { char str[100]; int i; printf( "Enter values :"); scanf("%s %d", str, &i); printf( "nYou entered: %s %d ", str, i); return 0; } Enter a value : seven 7 You entered: seven 7
  • 17.  C pre processor refers to a separate program which will be invoked by the compiler as first part of translation.  Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.  Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol. Source Code Preprocessor Compiler Object Code
  • 18.  The preprocessor provides the ability for the inclusion of header files.  Preprocessor directives are lines included in the code of programs preceded by a hash sign (#).  These lines are not program statements but directives for the preprocessor.  The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.
  • 19.  No semicolon (;) is expected at the end of a preprocessor directive.  Preprocessor directive can be extended by a backslash ().
  • 20. Few examples of preprocessor directives  #include<stdio.h>  #include<conio.h>  #include<math.h> etc.
  • 21. S.no Preprocessor Syntax Description 1 Header file inclusion #include <file_name> The source code of the file “file_name” is included in the main program at the specified place 2 Macro #define This macro defines constant value and can be any of the basic data types. 3 Conditional compilation #ifdef, #endif, #if, #else, #ifndef Set of commands are included or excluded in source program before compilation with respect to the condition 4 Other directives #undef, #pragma #undef is used to undefine a defined macro variable. #Pragma is used to call a function before and after main function in a C program
  • 22.  #include pre processor directive is used to include header files in the program.  If header file name is enclosed within angle brackets (), then compiler search this file only within its standard include directory.  Similarly, if header file name is enclosed within double quotes (“ ”) then compiler will search this file within and out side of its standard path. 1. Header file inclusion (#include)
  • 23. #include <stdio.h> void main() { printf("Hello, world!n"); getch(); } 1. Header file inclusion (#include) Example
  • 24.  In C/C++ programming language, Define directive is used for multi functions such as to define a symbol, to define a name constant or to define macros (short and fast processed code)  (a) To define a symbol,  (b)To define name and constants  (c) To define macros 2. Macro - Define Directive (#define)
  • 25. (a) To define a symbol,  In the first statement, NULL is a symbol which would be replaced with 0 in a program. Similarly, the symbol PLUS can be replaced with +. So following both statements will be work in the same way. 2. Macro - Define Directive (#define) C=A PLUS B; it will work same as C=A+B; #define NUL 0 #define PLUS +
  • 26. (b) To define name and constants  #define preprocessor can help to define a named constant. Such as 2. Macro - Define Directive (#define) #define INTEGER 5 #define CHARACTER A
  • 27. (c) To define macro  In C/C++ programming language, a macro is defined as a segment of text and it is very useful due to its readability or compact factors. Some examples of macros are 2. Macro - Define Directive (#define) #define pi 22.0/7 #define Area(r) 3.14*r*r  The first macro is very simple and its name can be used in any expression such as A= pi* 5. Similarly, second macro has a parameter r and it calculate the area.  If a macro is defined at more than one line then you need to place at the end of each line except last line. Symbol is used for continuation from next line.
  • 28. 2. Macro - Define Directive (#define) (c) To define macro value of height : 100 value of number : 3.140000 value of letter : A value of letter_sequence : ABC value of backslash_char : ? #include <stdio.h> #define height 100 #define number 3.14 #define letter 'A' #define letter_sequence "ABC" #define backslash_char '?' void main() { printf("value of height : %d ", height ); printf("value of number : %f ", number ); printf("value of letter : %c ", letter ); printf("value of letter_sequence : %s ", letter_sequence); printf("value of backslash_char : %c ", backslash_char); } Output:
  • 29.  In this type of preprocessor, #ifdef directive is used to check the existence of defined macros, constant name or symbol. For example, when we write following statement  The work of #ifndef directive is same as of #ifdef but there is slight difference. For #ifdef directive, if a symbol or named constant or macro has been undefined by using #undef then #ifdef will return false valu, but #ifndef will return true value for such case. 3. Conditional Compilation(#ifdef, #ifndef, #endif)
  • 30. 3. Conditional Compilation(#ifdef, #ifndef, #endif) Khalid is defined. So, this line will be added in this C file #include <stdio.h> #define Khalid 10 int main() { #ifdef Khalid printf("Khalid is defined. So, this line will be added in this C file"); #else printf("Khalid is not defined"); #endif return 0; } Output:
  • 31.  #undef preprocessor directive is used to undefined a macro, named constant or any symbol which has been defined earlier.  Unlike #include and # define directives, #undef directive can be used everywhere in a program but after the #define preprocessor. #undef pi #undef PLUS 4. Undefine Directives (#undef)