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

Function Part 2

                              C programming 


Type of function:

  • No return type no argument - void small ( )
  • return type & no argument  - int small ( )
  • No return type & argument - void small ( )
  • Return type & argument - int small ( int , int)

Advantages of function:

There are several advantages of function -
  1. Reduction in code redundancy
  2. Enabling code reuse
  3. Better readability
  4. Information hiding
  5. Improved debugging & testing
  6. Improved maintainability 

Clarification of function:

Function can be classified as -
  1. user defined function 
  2. Library function

1. Library function:

There are those functions whose functionality has already been developed by someone and are available to the user for use these are called library functions or pre defined function.
Ex. printf(), scanf(), sqrt(), pow() etc.

2. User defined function:

These are functions that are defined by the user at the time of writing a program the user. Develop the functionality by writing the body of the function also called programmer defined function.

Need of user defined function:

  • Facilitates top down modules programming approach .
  • Length of source program can be reduced
  • Easy to locate and isolate a specific logic.
  • A function can be used by many other programs.

Return type:

The return statement is used to return the result of the computation program control back to the calling function. There are three forms of return statement -

return i:

Used when function does not return any value. 

return expression :

 Used when function returns result of calling function to called function 

function name:

The rule for a function name is same as for a variable name.

Type of parameter:

It specifies the kind of parameter that are used in function for eg. int, char, float etc.

Number of parameter:

It specifies how many parameter are used in function. 

Ex.

Waf to add two numbers-

#incldue<stidio.h>
void sum (int,int)
main()
{
int a,b;
printf("Enter No.");
scanf("%d %d",&a,&b);
sum(a,b);
}
void sum (int c, int d)
{
int s;
s=c+d;
pritnf("Sum=%d",s);
}



Thank you,
keep supporting..............

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