Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

1 Programming Fundamentals

The document discusses the structure and components of a C++ program. It describes sections such as documentation, standard libraries inclusion, function declaration, definition, main function and explains the purpose and usage of each section.

Uploaded by

hlt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

1 Programming Fundamentals

The document discusses the structure and components of a C++ program. It describes sections such as documentation, standard libraries inclusion, function declaration, definition, main function and explains the purpose and usage of each section.

Uploaded by

hlt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Program Structure

• // Simple C++ program to display "Hello World"


• // Header file for input output functions
• #include<iostream>
• using namespace std;
• // main function -
• // where the execution of program begins
• int main()
• {
• // prints hello world
• cout<<"Hello World";
• return 0;
• }
• This section comes first and is used to document the logic
of the program that the programmer going to code.
• It can be also used to write for purpose of the program.
• Whatever written in the documentation section is the
comment and is not compiled by the compiler.
Documentation • Documentation section is optional since the program can
Section execute without them.
• Example:/* This is a C++ program to find the
• factorial of a number
• The basic requirement for writing this
• program is to have knowledge of loops
• To find the factorial of number
• iterate over range from number to one
• */
Linking Section
• Standard libraries section
#include <iostream>
• using namespace std;
• #include is a specific preprocessor command that effectively copies and pastes the
entire text of the file, specified between the angle brackets, into the source code.
• The file <iostream>, which is a standard file that should come with the C++ compiler, is
short for input-output streams. This command contains code for displaying and getting
an input from the user.
• This enables the programmer to use standard input, output, and error facilities that are
provided only through the standard streams defined in <iostream>. These standard
streams process data as a stream of characters, that is, data is read and displayed in a
continuous flow.
Definition Section

• It is used to declare some constants and assign them some value.


• In this section, anyone can define your own datatype using primitive data types.
• In #define is a compiler directive which tells the compiler whenever the message is
found replace it with “factorial\n” .
• Global declaration section:
• Here the variables and the class definitions which are going to be used in the
program are declared to make them global.
• The scope of the variable declared in this section lasts until the entire program
terminates.
• These variables are accessible within the user-defined functions also.
Function declaration section

It contains all the functions which our main functions need.


• Usually, this section contains the user-defined functions.
• This part of the program can be written after the main function but for this, write the function
prototype in this section for the function which for you are going to write code after the main
function.
• Function body section
• Cout << "hello world" << endl;
• Return 0;
• The return keyword tells the program to return a value to the function int main
• After the return statement, execution control returns to the operating system component that
launched this program.
• Execution of the code terminates here.
Main function section

• int main() {}
• The starting point of all C++ programs is the main function.
• This function is called by the operating system when your program is executed by the computer.
• { signifies the start of a block of code, ​and } signifies the end.
• Example:
• #include <iostream>
• using namespace std;
• int main() {
• cout << "Hello World!" << endl;
• return 0;
• }

You might also like