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

More Related Content

What's hot

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
JavaTpoint.Com
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
NishmaNJ
 
Lesson 7 io statements
Lesson 7 io statementsLesson 7 io statements
Lesson 7 io statements
Dr. Rupinder Singh
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
C programming language
C programming languageC programming language
C programming language
Mahmoud Eladawi
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
Programming in C
Programming in CProgramming in C
Programming in C
Nishant Munjal
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
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
Sivakumar R D .
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
C programming
C programmingC 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 dti2143alish sha
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
C Programming
C ProgrammingC Programming
C Programming
educationfront
 
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
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
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 Basics
Bharat Kalia
 

What's hot (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
 

Viewers also liked

Chicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATIONChicory BENEFITS AND CONTRAINDICATION
Chicory BENEFITS AND CONTRAINDICATION
Aura Gondayao
 
Herbs that stimulate hair regrowth
Herbs that stimulate hair regrowthHerbs that stimulate hair regrowth
Herbs that stimulate hair regrowth
zaracollins42
 
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
Mr.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
Naturogain
 
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 business
REHAN IJAZ
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
REHAN IJAZ
 
Career development interviews
Career development interviewsCareer development interviews
Career development interviews
REHAN 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 assignment
REHAN IJAZ
 
Programming Fundamentals lecture 3
Programming Fundamentals lecture 3Programming Fundamentals lecture 3
Programming Fundamentals lecture 3
REHAN IJAZ
 

Viewers also liked (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
 

Similar to Programming Fundamentals lecture 5

Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
Mehul Desai
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
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
tarifarmarie
 
C structure
C structureC structure
C structure
ankush9927
 
(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
atulchaudhary821
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
farishah
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
Muhammed Thanveer M
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
Nicole Ynne Estabillo
 
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
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramDeepak Singh
 

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

More from 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 system
REHAN IJAZ
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
REHAN IJAZ
 
Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1Introduction to artificial intelligence lecture 1
Introduction to artificial intelligence lecture 1
REHAN IJAZ
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
REHAN IJAZ
 
Programming Fundamentals lecture 4
Programming Fundamentals lecture 4Programming Fundamentals lecture 4
Programming Fundamentals lecture 4
REHAN IJAZ
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
REHAN IJAZ
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
REHAN IJAZ
 
Porposal on Student information management system
Porposal on Student information management systemPorposal on Student information management system
Porposal on Student information management system
REHAN IJAZ
 
Project on Student information management system
Project on Student information management systemProject on Student information management system
Project on Student information management system
REHAN IJAZ
 

More from 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
 

Recently uploaded

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.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)