While Loop in C++ Programming Language

Image
  While Loop in C++ Programming Language We have discussed about the entry-controlled loop or pre-tested loop previously in our blog posts. These statements or loops are used to repeat a piece of code for a specific number of times as per our program requirement. We have studied about the for loop already. Today in this blog post we are going to study about the while loop in C++ programming language. And we will look at how this while loop actually works and how we can stop it by making some condition false so that the loop might not run infinitely. We use while loop in C++ program when the number of iterations is not known in advance and depends on the condition. When we know exactly that how many times a loop should run then we use the for loop instead of while loop. Basic Syntax Of While Loop in C++ Programming Language Basic Working Of While Loop In C++ Programming Language Now we are going to discuss about the basic working of while loop in C++ programming....

How To Write Hello World Program In C++ Programming Language

 How To Write a Hello World Program In C++ Programming Language

In this post we will look at how a C++ program works. We will try make the example as simple as possible for the beginners so they can easily understand the basics of C++. We will write a simple C++ hello world program in C++ programming language which is considered as the very first program in almost every programming language.




A Brief Introduction to the C++ Programming Language

C++ is an object oriented programming language and it is an extension to C programming language. C++ is a general purpose programming language and it is also a case-sensitive language. C++ is very powerful programming language it has features of both low level and high level programming languages, and that is why it is called mid level programming language.

Hello World program in C++ programming language




Above is an example of a simple Hello World program in C++ programming language. Now let us look at the code, and I will take you through this code and explain each line of code step by step in an easy way so that beginners can understand it very easily.


Code Description

In the first two lines we used #include directive to include or give the reference of header files which are iostream and conio.h.

For now, consider these files as documents that we included in our C++ program, due to which we can use some functions and objects that are defined in these files.

These functions and objects include _getch() and cout which are defined in iostream and conio.h files.

In the third line, we used the using namespace std. This line indicates that we are using a namespace in this code which is named as std.

If we don't use or include std at the start of the code, then with every cout statement we have to write it like std::cout << "Hello World";

After that, we used the void main() function, which is the main part of our program. A C++ compiler always looks for this function with the name main(). This is the entry point for our C++ program.

cout<<"Hello world" is used to print a Hello World message to the console screen. With the help of the cout object, we can display output to the console screen.

And at last we used the _getch() function that holds the console screen and does not let it disappear after the successful execution of our program.

Congratulations, as always, we have implemented our first C++ program successfully.













Comments

Popular posts from this blog

How to run c project in visual studio community 2022

While Loop in C++ Programming Language

if and if else statement in C++ programming language