This document provides an overview of functions in the C programming language. It defines what functions are and their uses, including allowing code to be grouped and reused. It provides examples of basic function syntax and definition. It also covers function calling, parameters, return types, scope rules, and other key concepts like recursion, global variables, and header files. The goal is to teach the reader about functions as a fundamental building block in C programming.
Function is a set of statement which is designed to perform some specific task. Function gives functionality to programmer to use one module(task) for more times rather then write same code again and again....
Function is a set of statement which is designed to perform some specific task. Function gives functionality to programmer to use one module(task) for more times rather then write same code again and again....
IJRET : International Journal of Research in Engineering and Technology is an international peer reviewed, online journal published by eSAT Publishing House for the enhancement of research in various disciplines of Engineering and Technology. The aim and scope of the journal is to provide an academic medium and an important reference for the advancement and dissemination of research results that support high-level learning, teaching and research in the fields of Engineering and Technology. We bring together Scientists, Academician, Field Engineers, Scholars and Students of related fields of Engineering and Technology
Mountainbike-Urlaub 2016: Die schönsten Regionen in Österreich, Italien und der Schweiz für Urlaub mit dem MTB im Mountainbike Holidays Katalog. Geprüfte Mountainbike Hotels bieten zahlreiche Bike Services wie geführte Touren mit Mountain Bike Guides, Tourenberatung, e-MTB, Freeride und vieles mehr.
Getting the word out, generating buzz and building a reputation requires savvy, in-the-know networking and the ability to use the tools available to us. Effective use of social media utilities and other outlets can help take us from good to great. Learn about how to promote your organization and events more effectively through social media in order to increase your online presence and event attendance.
This presentation is a part of the COP2272C college level course taught at the Florida Polytechnic University located in Lakeland Florida. The purpose of this course is to introduce students to the C++ language and the fundamentals of object orientated programming..
The course is one semester in length and meets for 2 hours twice a week. The Instructor is Dr. Jim Anderson.
Library Functions, User defined functions, Recursion, Function declaration, Local and global variables, Use of array in function, Passing by Value, Passing by Address
https://github.com/ashim888/csit-c
1. C Programming
Language
By:
Yogendra Pal
yogendra@learnbywatch.com
Dedicated to My mother and Father
2. t
y
Keep your notebook with you.
Write important point and questions that comes in your mind
Solve Mind band exercise.
C
Rewind when not clear
Ask Questions by call or SMS or by mail
Keep Watching Keep Learning
THIS IS FUNCTIONS
2
3. Function
• 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
main().
4. Need
• Consider a problem:
– Write a program that take 3 numbers x, y, z as input
from user and calculate and print x5+y5+z5
5. General form
Return_type function_name(parameters)
{
statements;
return value;
}
• Return type : any data type.
• Function name : used to call the function.
• Parameters : zero or more variables.
6. An Example
int square(int num)
{
return num*num;
}
• This function accept an integer value and return its
square.
7. Function-Call
• Pass function_name and Parameters.
• Function performs a specific task that is given
to it.
• Result will return.
• Default return type is int.
• If you want to return noting use void.
10. More about function
• All variable defined inside functions are local
and known only in function defined.
• Parameters are used to communicate between
functions.
11. Why use functions?
• Make your problem modularize.
• Increase reusability.
• Avoid code repetition.
12. Function Prototype
• 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.
13. Problems
• 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.
14. Global Variable
• Global variables are defined outside of any
function.
• Available to many functions.
• Functions are always external.
• C does not allow functions to be defined inside
other functions.
• Any function may access an external variable
by referring to it by name.
14
15. Scope Rules
• File scope
– Identifier defined outside function, known in all
functions.
– Used for global variables, function definitions,
function prototypes.
• Function scope
– Can only be referenced inside a function body
– Used only for labels (start:, case: , etc.)
16. Scope Rules
• 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
17. Function calling
• Call by value
– Copy of arguments passed to function.
– Changes in function do not effect original.
– Use when function does not need to modify
arguments.
• Call by reference
– Passes original arguments
– Changes in function effect original variables.
18. Header Files
• Contain function prototypes for library
functions.
– Ex: conio.h, stdio.h, stdlib.h, math.h.
• Load with #include <filename> or
#include “filename”
19. Some standard header files
Standard Explanation
library header
<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.
19
20. Custom header files
• Create header file with function.
• Save filename.h
• Load in other files with #include “filename.h”.
• Reuse function
21. Recursion
• Functions that call themselves.
• Function launches a new copy of itself.
• Ex:
– Calculate factorial using recursion.
22. Mind Bend
• 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).
22
23. To get complete benefit of this tutorial solve all the quiz on
www.learnbywatch.com
For any problem in this tutorial mail me at
yogendra@learnbywatch.com
with the subject “C”
For Other information mail at
info@learnbywatch.com
Keep Watching Keep Learning
NEXT IS ARRAYS
23