Category: Functions in C

Coding Standards for Writing Functions 1

Coding Standards for Writing Functions

Whether its C programming language or C++ programming language or PHP, we should have a coding standard in place before starting with the code development. Coding standard is a predefined standard which should be followed during the code development which will improve the quality of the code. The coding standards varies from organization to organization. Each organization define their own coding standard and follow them to achieve the desired code quality. Here, we will define a coding standard for writing functions. Coding Standards for Writing Functions A function name should be preceded by fn The first character in the function...

How does using functions make writing large programs easier? 1

How does using functions make writing large programs easier?

Consider a program with 1000 lines. It is much easier to write a properly designed program consisting of 20 50-line functions than it is to write a program consisting of one 1000-line main program. Functions can be written, tested, and understood independently of one another. You can write a function, test it, and convince yourself that it is correct without worrying about the other functions in your program. It is much easier to get your mind around a 50-line thing than a 1000-line thing. Another benefit is that code can be reused between projects. If someone has previously written a...

Function Prototype in C Language 7

Function Prototype in C Language

As we all know, before using a variable we need to declare it. Similarly, before using a function we need to declare the function. This declaration of the function is called as function prototyping. Consider the above program. There is one statement before the main() function. The statement is: float fnGetAverage(int, int); This statement is called function prototype. By doing this we are telling the compiler that we will use the function having following features: The function name would be fnGetAverage The function will return float value The function will contain two int arguments If we do not wish to...

Function declaration and Prototype in C Programming Language 19

Function declaration and Prototype in C Programming Language

By default, any C function returns an int value. If we want that the function should return a value other than int then we need to explicitly mention it in the function definition. Let us understand this using an example. Example 1:

Output: