See a problem in else if statement

Dangling else problem

Image
Hello, This problem comes when we use else if statement and do some mistake more describe is given below......... Dangling else problem: One of the major problem with nested if is dangling else problem. The problem arises when both outer if statement inner if statement might pair with common else statement. Thus the compiler is not able to judge to pair the else with which statement. The solution to this problem is given by the compiler that it pairs else with the recent if thus sometimes giving wrong result.                                           Hence the programmer should put early bracket wherever required. This post is may very short because my only aim was to describe this problem. Thank you, Keep supporting............. 

Main function ,else if lader and nesting of loop

                                C programming


main function:

Main function is a specially recognized function in C programming.Every program must have a main function to indicate where the program has to began its execution. While it is possible to code any program utilizing only main function. It leads a numbers of problem. This leads a number of problem. This leads to increase in completing and as  a result the task of debugging testing and maintaining  becomes difficult. If a program is divided into functional posts than each past may be independently managed.

Else if lader-

if(expression)
{
statement 1;
.
statement n;
}
else if (expression )
{
statement 1;
.
statement n;
}
else if
{
statement 1;

statement n;
}
else
{
statement 1;

statement n;
}

If the expression 1 evaluate to be true , the if block is executed otherwise expression 2 is checked and if it evaluated to be true that particular else if block is executed and if the expression 1 is false  the else part is executed.


Nesting of if:

Using an if else construct with in another if or else construct is called nesting of if.

syntax:
if (exp 1)
{
statement 1;

statement n;
}
  if (exp 2)
  {
   statement n;
  }
 else 
{
statement n;
}
}
When inside if block another if is use and also we can say when we have many conditions then use nesting of if.

Thank you;
For learn complete C programming go to last post of my blog and start learning of C.

Comments

Popular posts from this blog

Libraray Fine Hackerrank solution in C || Balanced Brackets Hackerrank solution in C

Permutations of Strings hackerrank solution in C || Permutations of Strings

Introduction to C part 2