answersLogoWhite

0

What is nested if in c plus plus?

User Avatar

Anonymous

12y ago
Updated: 8/17/2019

A nested if is simply if statement within the body of another if statement. For example:

int x = 1;

int y = 1;

if( !x )

{

if( !y )

std::cout << "both x and y are zero" << std::endl;

else

std::cout << "x is zero but y is not" << std::endl;

}

else

{

if( !y )

std::cout << "x is not zero but y is zero" << std::endl;

else

std::cout << "neither x nor y are zero" << std::endl;

}

The above is essentially the same as saying:

if( !x && !y )

std::cout << "both x and y are zero" << std::endl;

else if( !x && y )

std::cout << "x is zero but y is not" << std::endl;

else if( x && !y )

std::cout << "x is not zero but y is zero" << std::endl;

else

std::cout << "neither x nor y are zero" << std::endl;

However, the nested if format is quicker to execute because both x and y are evaluated once and once only, whereas the latter needs to evaluate both x and y continually until a matching condition is found.

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is nested class in c plus plus?

s.


What is the difference between n-- and --n in C plus plus statement?

If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.


Can include files be nested in c?

Yes, include files can be nested in C and C++. In fact, most library implementations do just that.


How do you do nested strcutres program in c plus plus?

As its name suggests, a nested structure is a structure which contains another within it. Here is an example in which the "nApple" structure is nested withing the "nTree" structure: #includestruct nApple{int stem;int skin;};struct nTree{int leaves;nApple redDelicious;nApple grannySmith;};


Can you have nested header files in C?

Yes.


What is the definition of 'nested' in C programming?

In C a structure within a structure is called nested. For example, you can embed a while loop in another while loop or for loop in a for loop or an if statement in another if statement.


In C which loop is embedded within another loop?

The nested loop.


What is nesting in C programming?

Nesting can be a very handy tool in C++, but should be avoided if possible.C++ gives us If statements, For loops and many other things. These can be nested. For example:A nested If statement://outer if statementIf( this is true ){//nested if statementif( this is also true ){//do something}else{//do something else}}


Syntax of nested if in c?

If(condition) { if-else statement; } else { if-else statement; }


What is the compound in c language?

compound c language is complicated where we need to use many nested functions and loops


Why doesn't C have nested functions?

Nested functions are used in some languages to enclose multiple functions and variables into a container so that individual function and variable are not seen from outside. In,C this can be done by putting such functions in a seperate source file.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c