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

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

 How if else-if else ladder statement work in the C program.

In C programming or any other programming language, there is a concept of control statements or conditional statements. In one of our previous blog posts, we shed some light on the if else statement in the C program. In this post, we will cover the if else-if else ladder statement, which is used when multiple conditions need to be addressed. No, we are going to look at the syntax of the if else-if else ladder statement.



Syntax of if else-if else ladder statement

if (condition) 

{

// code to be executed if the condition is true

}

else if (condition)

{

// code to be executed if the condition is true

}

else if (condition

{

// code to be executed if the condition is true

}

else 

{

// code to be executed if none of the conditions is true

}


The if else-if else ladder statement is very similar to the if else statement. The main difference is the addition of an else-if part in it. In the above syntax part, we used two else-if conditions, it is according to our requirement that how many different conditions are needed to be addressed. We can use multiple else-if conditions according to our requirements.

Below is the sample code given for the if else-if else ladder statement. We are going to take a number as input and then we are going to implement the if else-if else statement.



In the above coding segment, we are entering a number, and we are going to check that the entered number is equal to 10. We are using the if condition and going to print the message within the if block that the entered number is equal to 10.



In the above coding segment if the entered number is 20 then we are going to use the else-if condition and run the code block of else-if which prints that the entered number is equal to 20, and the same logic will be used for the remaining else-if conditions and their code blocks. 



And at last, if the entered number is not equal to 10, 20, 50, or 100 then the else part will run and prints that the entered number is not equal to 10, 20, 50, or 100.


The Main difference between if and else-if statement

If we use multiple if conditions in our program, our program will check each and every if condition even if the very first if condition is true still the program will check all the remaining if conditions. Whereas in the else-if condition if the very first else-if condition is true the program will not check the remaining else-if conditions at all.

Congratulations we have successfully implemented the if else-if else ladder statement in our program.

Comments

Popular posts from this blog

How to add two numbers in C programming language