C++ PROGRAM STRUCTURE
A C++ program is organized in a particular and unique way. The following components make up a program in C++:
Header File Declaration Section
|
Global declaration Section
|
Class Declaration
And
Method Definition Section
|
Main Function
|
Ø Header File Declaration Section:-
Example of header file in a simple hello world program:-
#include <iostream.h>
#include <conio.h>
void main()
{
cout<<”Hello world”;
getch();
}
|
Output:-
Hello world
|
In this program we use a two header file:-
<iostream.h>
<conio.h>
The header file <iostream.h> is input
output stream, it is use to control the input output operation in C++ language.
Another header file <conio.h> is console
input output, it is used in an old DOS compilers to create text user
interfaces.
Ø Global declaration Section:-
Global declaration is also known as a global variable in a C++. It is a variable that declare outside of any function, and they can be accessed on any function in the program.
The simple definition of global declaration is:-
The variable which are declared outside of the function and accessed from all function including main function are known as GLOBAL VARIABLE AND DECLARATION
Example of global variable given blow:-
#include<iostream.h>
#include<conio.h>
Int
a=10; // this is global
variable and declaration
Void
main() //main function()
{
Int
b,c;
B=20;
C=b+c;
cout<<”The
value of C is :”<<C;
getch();
}
|
Output:-
The
value of C is 3
|
Ø Class Declaration And Method Definition Section:-
Example of class declaration and method definition section:-
class
ClassName
{
Access
specifier: // can
be private, public or protected
Data
member; //
Variable to be used
Member
function() {} // Method to access data members
); // Class name ends with semicolon
|
ex:
|
Class is a keyword and ClassName is a name of the class
Ø Main Function:-
A function is a group of statements that together perform a task. Every C++ program has at least one function, which is main(), and all the most trivial programs can define additional functions. The main function can in-turn call other function. When main calls a function
Two type of main function in a c++ are given blow:-
1. Null type (void)Int: it is return type of a main function, at that time main() return integer type value.
Simple example of main():-
#include<iostream.h>
#include<conio.h>
Void main()
{
Cout<<”Hello
world”;
getch();
}
|
Output:-
Hello world
|
Data science & data analyst
- Data Cleaning and Preprocessing in Data Science
- Advanced Data Analysis Techniques: Unlocking Insights from Data
- Data Visualization Techniques in Data Science
- Descriptive Statistics in Data Sci
- Data Science Tools and Techniques
- Scope of Data Science
- Why learn Data Science? | Why Data Science?
- Impact of Data Science
- The Importance of Data in Science | Introduction to Data Science
- What is Data Analysis | Data Analyst for Beginners
C++
- Introduction of C++ || Definition of C++
- Brief history of C++ || history of C++
- Features of C++ || why we use C++ || concept of C++
- Concept of OOP || What is OOP || Object oriented programming language
- Difference Between OOP And POP || Different Between C and C++
- Characteristics of C++
- Interesting fact about C++ || Top 10 interesting fact about C++
- C++ Program Structure
- Writing first program in C++ || how to write hello world in C++
- Basic Data Type And Variable In C++
- Identifier in C++
- Keywords in C++
- Token in C++
- Comment in C++
- Constant in C++
- Modifier in C++
- Taking User Input in C++ | User input in C++
- Input Output Operator In C++
- C++ Operators | Operator in programming language
- How to Add two number in C++
- Polymorphism in C++
- Compile Time Polymorphism in C++
- Function overloading in C++
- Operator Overloading in C++
- What are Control Structures in C++ || Understanding Control Structures in C++ | How to use if, else, switch
- What are Functions and Recursion in C++ | How to Defining and Calling Functions
- Class in C++
- Object in C++