User defined Functions in C - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorial, we are going to learn about the User defined functions in C.
User-defined functions are the functions that are defined by the user at the time of writing the program. Functions are made for code re-usability and for saving time and space.
In C, main() is the user-defined function and first calling function in any program. main() is a special function that tells the compiler to start the execution of a C program from the beginning of the function main().
An identifier other than keywords followed by parenthesis is recognized as a function name by the compiler.
To make use of the user-defined function the programmer must be able to know the following 3 concepts.

Define a Function (or) Function Definition
Function Prototype (or) Function Declaration
Calling a Function (or) Invoke a Function

Define a Function (or) Function Definition
Function Prototype (or) Function Declaration
Calling a Function (or) Invoke a Function
A function definition describes what a function does, how its actions are achieved, and how it is used. It consists of a function header and a function body.
The general format of defining a function is
return_type function_name(parameters list) {
  //Local variable declarations
  //Executable statements
  return(expression);
}
The first line which heads the function is known as the function header. The function header should not end with a semicolon (;) in defining a function.
The function body follows the function header and it is always enclosed in braces. The body of the function is a combination of local variable declarations and executable statements.
Here the statements describe the actions to be performed by the function. The body of function definition is also known as a block or compound statement. The elements specified within the parenthesis of the function name are known as parameters or arguments.
The general format of defining a function is
return_type function_name(parameters list) {
  //Local variable declarations
  //Executable statements
  return(expression);
}
The return_type specifies the data type of the value returned by the function. The return_value may be of the primitive data type or empty data type.
If return_type is omitted then the default return_type of any function is int. A void is specified in the place of return_type if the function returns no value. function_name is any valid identifier. It can’t begin with an underscore because such names are reserved for the use of the C library.
The arguments in the parameter_list are known as formal parameters. Zero or more parameters may be used. Each parameter must be preceded by its data type.
More than one parameter must be separated by commas. Parameters are used to pass the values into the function definition. For parameterless functions, the keyword void is placed within the parenthesis of the function name. It consists of the keyword return followed by an expression within the block and it returns only a single value to the calling function when the function returns a value.
A value or an expression may follow a return if the function returns a value; otherwise, nothing follows return. The syntax of the return statement is
return(expression); (Or) return expression;
The following points must be kept in mind while defining a function.
A function cannot be defined more than once in a program.
One function cannot be defined within another function definition.
Function definitions may appear in any order.
Built-in functions are predefined and they are available in the C library that is supplied along with the compiler.
Whenever a function is invoked within another function it must be declared before use. Such declaration is known as function declaration or function prototype.
Function declaration always ends with a semicolon (;). The general format of the function prototype is
return_type function_name(parameter_list);
In the above function declaration, the parameter names in the parameter_list are optional.
Hence, it is possible to have the data type of each parameter without mentioning the parameter name as shown below.
return_type function_name(data_type, data_type, data_type,...., data_type);

A parameterless function is declared by using void inside the parenthesis as
return_type function_name(void);
For user understandability, all the function declarations are specified before the main() function. A function is invoked to make use of it. The general format of a function call is
function_name(var_1, var_2 .... var_n);
Where var_1, var_2,..., var_n are argument expressions. For a parameterless function, there is no argument in the function call also.
The arguments var_1, var_2,..., var_n in a function call is called actual arguments.
If a function returns a value, the function call may appear in any expression, and the returned value used as an operand in the evaluation of the expression.
gnu – C functions
gnu – Function Definitions
C Program Structure
Happy Learning 🙂

C – Derived and User Defined Data Types
Functions in C
PHP Functions Example Tutorials
user defined exceptions in Java
User defined Exceptions in Python
User defined sorting with Java 8 Comparator
Python Decorators – Classes and Functions
JQuery Callback Functions Example Tutorial
Hello World Java Program Example
PHP String functions Example Tutorials
Different ways to use Lambdas in Python
C – Header Files & Preprocessor Directives
C – Type Conversions
What are Python default function parameters ?
Java Class Example Tutorials

C – Derived and User Defined Data Types
Functions in C
PHP Functions Example Tutorials
user defined exceptions in Java
User defined Exceptions in Python
User defined sorting with Java 8 Comparator
Python Decorators – Classes and Functions
JQuery Callback Functions Example Tutorial
Hello World Java Program Example
PHP String functions Example Tutorials
Different ways to use Lambdas in Python
C – Header Files & Preprocessor Directives
C – Type Conversions
What are Python default function parameters ?
Java Class Example Tutorials
 


Δ
 C – Introduction
 C – Features
 C – Variables & Keywords
 C – Program Structure
 C – Comment Lines  & Tokens
 C – Number System
 C – Local and Global Variables
 C – Scope & Lifetime of Variables
 C – Data Types
 C – Integer Data Types
 C – Floating Data Types
 C – Derived, Defined Data Types
 C – Type Conversions
 C – Arithmetic Operators
 C – Bitwise Operators
 C – Logical Operators
 C –  Comma and sizeof Operators
 C – Operator Precedence and Associativity
 C – Relational Operators
 C Flow Control – if, if-else, nested if-else, if-else-if
 C – Switch Case
 C Iterative – for, while, dowhile loops
 C Unconditional – break, continue, goto statements
 C – Expressions and Statements
 C – Header Files & Preprocessor Directives
 C – One Dimensional Arrays
 C – Multi Dimensional Arrays
 C – Pointers Basics
 C – Pointers with Arrays
 C – Functions
 C – How to Pass Arrays to Functions
 C – Categories of Functions
 C – User defined Functions
 C – Formal and Actual Arguments
 C – Recursion functions
 C – Structures Part -1
 C – Structures Part -2
 C – Unions
 C – File Handling
 C – File Operations
 C – Dynamic Memory Allocation
 C Program – Fibonacci Series
 C Program – Prime or Not
 C Program – Factorial of Number
 C Program – Even or Odd
 C Program – Sum of digits till Single Digit
 C Program – Sum of digits
 C Program – Reverse of a number
 C Program – Armstrong Numbers
 C Program – Print prime Numbers
 C Program – GCD of two Numbers
 C Program – Number Palindrome or Not
 C Program – Find Largest and Smallest number in an Array
 C Program – Add elements of an Array
 C Program – Addition of Matrices
 C Program – Multiplication of Matrices
 C Program – Reverse of an Array
 C Program – Bubble Sort
 C Program – Add and Sub without using + –