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

Image
  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...

for loop in C programming language for beginners

 for loop in C programming language for beginners


In programming languages, we have control statements that are used to control the behavior of the programs as per user requirements. One of these control statements is in a for loop that we use to iterate the piece of code several times as per user requirement or the programmer's logic. The most common use of a for loop is traversing data structures from beginning to end. One such example of data structures is the arrays and linked lists. Basically, we use a for loop in the conditions when we are sure about the exact number of times the block of code is to be iterated. In such situations, it is preferred to use the for loop.



Syntax of for loop in c:


for(expression1; expression2; expression3)

{

// block of code to be executed here

}


Now if we look at the syntax of the for loop it contains for keyword and round brackets in which there are three expressions given which are separated by a semicolon (;) symbol. The first expression is the part where we declare and initialize the loop variable. The second expression is the condition that we make according to our logic or requirement and this second expression determines how many times this for loop will iterate. The third expression is the part where we increment or decrement the loop variable as per our requirement and logic.


C++ for loop simple example:





Explanation of the above for loop Example:

This is a simple example that explains the working of for loop in c programming language.

In this example, we are going to print the numbers from 1 to 10 in the console screen using a for loop.

In the main function, we have a for loop which contains three expressions. In the first expression, we declared and initialize the variable I of type int and value 1 i.e, int i = 1;

The second expression is the part where we define the variable condition I value should be less than or equal to 10 i.e., i <=10. This expression will determine how many times this for loop will iterate.

In the third expression part, we increment the value of the i variable using the ++ operator like this i++ which simply means i = i + 1.

In this, for loop body, we simply print the numbers in the console screen from 1 to 10 using the print() function in C programming language.


Congratulations we have successfully implemented the for loop using C programming language.

Comments

Popular posts from this blog

How if else-if else ladder statement works in C program.

How to add two numbers in C programming language