Control structures in C++

0
34
datatypes in C++
Comparing two Numbers in C++

Control structures in C++ also called the decision makers. In C++ We have control structures which are helpful in programs which needs a little bit concept of decision making between different conditions. For instance we are comparing two things, we use the idea that if both things are the same the result will be positive, while if both are different the result will be negative.this concept can be used in C++ codes as well.the details of some control structures used in C++ are:.ie

  • “if” structure

–        Make decision based on truth or falsity of condition

  • If condition met, body executed
  • Else, body not executed.

These conditions are made using the following operators:
–        Equality and relational operators

–        Same level of precedence, Associate left to right

–        Same level of precedence, Associate left to right

Now you can get clear idea of control structures in C++ at the following example:

e.g

int x ;

cin>>x;
if(x == 1)
{
cout<<“your result is 1”;
}

else
{
    cout<<“your result is wrong”;
}

Here the “if”structure will check, whether the value entered by the user for the variable “x” is 1 or not, if the value is 1, it will execute the data present in the braces( {} ) of conditional structure “if”. On the other hand if the value entered is not 1, the the “if” the  structure is considered “Fasle” and in this case the data in the “else” control structure will be executed. It is very important to know that in further programs the use of control structures is very very important. the concept of this will get more clear in further examples.it is sure that it is very helpful further, so if We have control structures in C++, then no worries.

 

datatypes in C++
Comparing two Numbers in C++

Leave a Reply