C প্রোগ্রামিং এর বিভিন্ন ধরনের Function ও তাদের নামকরণের পদ্ধতি

Submitted by tushar pramanick on Mon, 02/25/2013 - 10:25

Details of a C Function

Functions are the building blocks of C programs. Besides the standard C library functions, you can also use some other functions made by you or another programmer in your C program. In Chapte 02 you saw the main() function, as well as two C library functions, printf() and exit(). Now, let's have a closer look at functions.

 

As shown in Figure 3.1, a function consists of six parts: the function type, the function name, arguments to the function, the opening brace, the function body, and the closing

 

Figure 3.1. The anatomy of a function in the C language. brace.

The six parts of a function are explained in the following sections.

 

Determining a Function's Type

The function type is used to signify what type of value a function is going to return after its execution. In Hour 2, for instance, you learned that the default function type of main() is integer. You also learned how to change the function type of main() to void so that the main() function does need to return any value.

 

In C, int is used as the keyword for the integer data type. In the next hour, you'll learn more about data types.

 

Giving a Function a Valid Name

A function name is given in such a way that it reflects what the function can do. For instance, the name of the printf() function means "print formatted data."

 

There are certain rules you have to follow to make a valid function name. The following are examples of illegal function names in C:

Illegal Name The Rule
2 (digit) A function name cannot start with a digit.
* (Asterisk) A function name cannot start with an asterisk.
+ (Addition) A function name cannot start with one of the arithmetic signs that are reserved C keywords.
. (dot) A function name cannot start with ..
total-number A function name cannot contain a minus sign.
account'27 A function name cannot contain an apostrophe.

 

Some samples of valid function names are as follows:

  • file2send
  • big_score
  • _fast_download
  • relation2
  • sample2copy
  • abcdef

 

Comments

Related Items

Adding More Expressions into for

Adding More Expressions into for

The C language allows you to put more expressions into the three expression fields in the for statement. Expressions in a single expression field are separated by commas.

The Null Statement

The Null Statement

Looping Under the for Statement

Looping Under the for Statement

The general form of the for statement is

for (expression1; expression2; expression3) {
   statement1;
   statement2;
   .
   .
   .
}

Using Nested Loops

Using Nested Loops

You can put a loop inside another one to make nested loops. The computer will run the inner loop first before it resumes the looping for the outer loop.

Listing 7.7 is an example of how nested loops work.

 

The do-while Loop

The do-while Loop

You may note that in the for and while statements, the expressions are set at the top of the loop. However, in this section, you're going to see another statement used for looping,