Dedicated to My mother and Father
Keep your notebook with you.
Write important point and questions that comes in your mind
Solve Mind band exercise.
Rewind when not clear
Ask Questions by call or SMS or by mail
Keep Watching Keep Learning
THIS IS FUNCTIONS
• Allow us to group commonly used code into a
compact unit that can be used repeatedly.
• main() function is must in each program.
• Other functions call directly or indirectly from
• Consider a problem:
– Write a program that take 3 numbers x, y, z as input
from user and calculate and print x5+y5+z5
• Return type : any data type.
• Function name : used to call the function.
• Parameters : zero or more variables.
int square(int num)
• This function accept an integer value and return its
• Pass function_name and Parameters.
• Function performs a specific task that is given
• Result will return.
• Default return type is int.
• If you want to return noting use void.
More about function
• All variable defined inside functions are local
and known only in function defined.
• Parameters are used to communicate between
Why use functions?
• Make your problem modularize.
• Increase reusability.
• Avoid code repetition.
• Used to validate function.
• Prototype only needed if function definition
comes after use in program.
– Ex: int maximum(int, int, int);
• Write a function that return the maximum value
among three integers.
• Write a function to calculate the factorial value
of an integer entered through the keyboard.
• Write a function power(a, b), to calculate the
value of ab
• Any year is entered through the keyboard.
Write a function to determine whether the
year is a leap or not.
• Global variables are defined outside of any
• Available to many functions.
• Functions are always external.
• C does not allow functions to be defined inside
• Any function may access an external variable
by referring to it by name.
• File scope
– Identifier defined outside function, known in all
– Used for global variables, function definitions,
• Function scope
– Can only be referenced inside a function body
– Used only for labels (start:, case: , etc.)
• Block scope
– Identifier declared inside a block
• Block scope begins at definition, ends at right brace
– Used for variables, function parameters (local
variables of function)
– Outer blocks "hidden" from inner blocks if there is a
variable with the same name in the inner block
• Function prototype scope
– Used for identifiers in parameter list
• Call by value
– Copy of arguments passed to function.
– Changes in function do not effect original.
– Use when function does not need to modify
• Call by reference
– Passes original arguments
– Changes in function effect original variables.
• Contain function prototypes for library
– Ex: conio.h, stdio.h, stdlib.h, math.h.
• Load with #include <filename> or
Some standard header files
<float.h> Contains the floating point size limits of the system.
<limits.h> Contains the integral size limits of the system.
<locale.h> Contains function prototypes and other information that enables a program to be
modified for the current locale on which it is running. The notion of locale enables
the computer system to handle different conventions for expressing data like dates,
times, dollar amounts and large numbers throughout the world.
<math.h> Contains function prototypes for math library functions.
<stdio.h> Contains function prototypes for the standard input/output library functions, and
information used by them.
<stdlib.h> Contains function prototypes for conversions of numbers to text and text to
numbers, memory allocation, random numbers, and other utility functions.
<string.h> Contains function prototypes for string processing functions.
<time.h> Contains function prototypes and types for manipulating the time and date.
Custom header files
• Create header file with function.
• Save filename.h
• Load in other files with #include “filename.h”.
• Reuse function
• Functions that call themselves.
• Function launches a new copy of itself.
– Calculate factorial using recursion.
• Write a function table(int num) that print the
table of the number that is passed to it.
• Write a function table_atob(int a, int b) that
accept two numbers a and b as an input and
call table(int num) print the tables from a to b.
• Write a function that validate the input a and b
entered in the function table_atob(int a, int b).
To get complete benefit of this tutorial solve all the quiz on
For any problem in this tutorial mail me at
with the subject “C”
For Other information mail at
Keep Watching Keep Learning
NEXT IS ARRAYS