Programming in C: Unit III (a): Functions

Function Definition

Programming in C

When a function is defined, space is allocated for that function in the memory. A function definition comprises two parts:Function header,Function body

FUNCTION DEFINITION

When a function is defined, space is allocated for that function in the memory. A function definition comprises two parts:

• Function header

• Function body

Programming Tip: It is an error to place a semicolon after the function header in the function definition.

The syntax of a function definition can be given as:

 return_data_type function_name (data_type variable1, data_type variable2, ...)

{

………...

statements

…….......

return (variable);

}

The number of arguments and the order of arguments in the function header must be same as that given in the function declaration statement.

Programming Tip: The parameter list in the function definition as well as function declaration must match.

While return data_type_function_name (data_type variable1, data_type variable2,..) is known as the function header, the rest of the portion comprising of program statements within {} is the function body which contains the code to perform the specific task.

The function header is same as function declaration. The only difference between the two is that a function header is not followed by a semicolon. The list of variables in the function header is known as the formal parameter list. The parameter list may have zero or more parameters of any data type. The function body contains instructions to perform the desired computation in a function.

Programming Tip: A function can be defined either before or after main().

The function definition itself can act as an implicit function declaration. So the programmer may skip the function declaration statement in case the function is defined before being used.

Note

The argument names in the function declaration and function definition need not be the same. However, the data types of the arguments specified in function declaration must match with that given in function definition.

Programming in C: Unit III (a): Functions : Tag: : Programming in C - Function Definition


Programming in C: Unit III (a): Functions



Under Subject


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation



Related Subjects


Professional English II

HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Statistics and Numerical Methods

MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation


Engineering Graphics

GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Physics for Electrical Engineering

PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Basic Civil and Mechanical Engineering

BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Electric Circuit Analysis

EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Physics for Electronics Engineering

PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Electrical and Instrumentation Engineering

BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Circuit Analysis

EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Materials Science

PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Physics for Civil Engineering

PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Basic Electrical, Electronics and Instrumentation Engineering

BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Physics for Information Science

PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation