"Hello World!" 1st C++ Program And Basic Structure For Beginners

Write your 1st simplest program of C++ in any compiler as beginner. Learn basic structure of Hello World in C++ Program.

For the beginners, programming is not easy. But on the other hand, it can be the easiest thing in the word just like your 1st program in C++ which is called "Hello World!". At the start, we will write a code to display only "Hello World!" on the screen. This is the simplest program of C++ and through this program code, we can understand the basic structure of C++. Writing a code in a text editor like notepad is possible but there saving the file with correct extension is necessary i.e(.CPP, .C .CP).
 Simplest Program of C++ Hello World
Simplest Program of C++

In this post, we will discuss our 1st program in C++ "Hello World!" and its structure to understand it deeply. So let's start to write out 1st code in C++.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
cout<<"Hello World!";
getch();
};
Running the program on online IDE or compilers like Dev C++ will show a message on the screen of Hello World!. there are 2 parts which are Header Files and Main Function. further explanation of main function and division in parts is possible but for now, we are gonna focus on these 2 parts of the code.

Basic Structure of C++:

C++ is case sensitive language. If you want to learn then this is the most important rule you have to remember always. A little mistake in lower case or upper case will make your program faulted and you will see errors in it.
Almost every C++ statement (expect class definition and main function) ends with a semicolon. As you can see from the start of the program to end of the program, every line is ending with a semicolon.

In the 1st part, we have lines started with (#) sign which indicates that this line contains directories of C++. In directories, there are pre-defined words and their actions are stored. Above in program, cout<< means to show the message on the screen. How will compiler know that what should I do when there's an instruction came called cout<<?  These instructions are stored in library files which we include in the program by writing #include<iostream>. At the end of the program, we have getch(); word and we are using this word for holding the screen (using of return 0; is also a good practice for holding screen).  For using getch(); we must add the library of #include<conio.h>. libraries have all information about inputs and outputs of the program.

Why we use namespace std;? Well! std stands for standard and if you don't declare namespace std in the start then you have to write std:: in every input-output instruction in the whole program. For example, if you don't declare std in start then for output you will write the statement like this.
std::cout<<"Hello World!";
By declaring we just need to write.
cout<<"Hello World!";
Same as the cout statement, every cin>> instruction is also required namespace std. Declaring this at the top is good practice and quite helpful as well.

2nd part of the program is called the main function which is started with int main() where the actual program exists. Each and everything we perform will be done by this part of the program. We can set a model of instruction in class or structure which is used in Objection Oriented Programming but to execute that model of instructions, we must define some instruction into the main function of C++. Every function in C++ starts with the type and name of the function as we wrote in above program. To write instructions, we must type opening braces { and closing braces } and every line of code must between {} braces.  Any type of instruction written out of braces of the main function will not be executed.

I hope you will understand the 1st simple program and its structure. As being a beginner, it's difficult to understand the code in the start but when you got grip on it, its become the piece of cake.
Do you have any queries? Feel free to ask in comments. 

COMMENTS

BLOGGER: 1
Loading...
Name

Books,18,C++ Projects,10,C++Tutorials,1,Java-Projects,3,PHP-Projects,5,
ltr
item
Source Code-Projects-Tutorials: "Hello World!" 1st C++ Program And Basic Structure For Beginners
"Hello World!" 1st C++ Program And Basic Structure For Beginners
Write your 1st simplest program of C++ in any compiler as beginner. Learn basic structure of Hello World in C++ Program.
https://3.bp.blogspot.com/-DMTtBEf3vYM/WyLLsg-q4OI/AAAAAAAAAYg/17vXDNm4HBU5hALWdWvLK7wuzG-hXOWOACLcBGAs/s320/Hello%2BWorld.jpg
https://3.bp.blogspot.com/-DMTtBEf3vYM/WyLLsg-q4OI/AAAAAAAAAYg/17vXDNm4HBU5hALWdWvLK7wuzG-hXOWOACLcBGAs/s72-c/Hello%2BWorld.jpg
Source Code-Projects-Tutorials
https://www.eprogramlab.com/2018/06/hello-world-1st-c-program-and-basic-structure.html
https://www.eprogramlab.com/
https://www.eprogramlab.com/
https://www.eprogramlab.com/2018/06/hello-world-1st-c-program-and-basic-structure.html
true
8265958001701134289
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy