What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer.

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

User Defined Functions
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use.
Spring Semester 2013 Lecture 5
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
Lecture 8. MIPS Instructions #4 – Branch Instructions #2
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Functions Quick Review What is a Function? A module of code that performs a specific job. Examples: Function that determines the maximum of two numbers.
Chapter 6: User-Defined Functions I
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
CS 201 Functions Debzani Deb.
Chapter 6: User-Defined Functions I
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Chapter 6: Functions.
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Functions in C Programming Dr. Ahmed Telba. If else // if #include using namespace std; int main() { unsigned short dnum ; cout
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
CPS120: Introduction to Computer Science Functions.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
CPS120: Introduction to Computer Science Lecture 14 Functions.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Functions g prototypes g arguments g overloading g return values part I Re-read Section 1.2.
FUNCTIONS IN C++. DEFINITION OF A FUNCTION A function is a group of statements that together perform a task. Every C++ program has at least one function,
1 Remember: Examination is a chance not ability. By ILTAF MEHDI, IT LECTURER, MIHE, KATR-E-PARWAN BRANCH, KABUL.
FUNCTION Dong-Chul Kim BioMeCIS UTA 12/7/
User defined functions
FUNCTIONS A function is a set of instructions that can perform a specific task accordingly. A function is a program that performs a specific task according.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Function Overloading and References
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Function prototype A function must be declared before it can be referenced. One way to declare a function is to insert a function prototype before the.
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
CSci 162 Lecture 8 Martin van Bommel. Large-scale Programming Up to now we have been writing relatively short programs to solve simple problem Want to.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
Programming Fundamentals Enumerations and Functions.
Functions Chapter 5. Function A set of instructions that are designed to perform specific task. A complete and independent program. It is executed by.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
Functions + Overloading + Scope
Chapter 7: Function.
Chapter 6: User-Defined Functions I
-Neelima Singh PGT(CS) KV Sec-3 Rohini
CSC113: Computer Programming (Theory = 03, Lab = 01)
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
CSC113: Computer Programming (Theory = 03, Lab = 01)
Functions in C Mrs. Chitra M. Gaikwad.
Tejalal Choudhary “C Programming from Scratch” Function & its types
S. Kiran, PGT (CS) KV, Malleswaram
CSC1201: Programming Language 2
User Defined Functions
Functions Chapter 3 of the text Motivation:
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Chapter 6: User-Defined Functions I
CS149D Elements of Computer Science
In C Programming Language
CSC1201: Programming Language 2
Functions Imran Rashid CTO at ManiWeber Technologies.
Presentation transcript:

What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer. It can be called anywhere in the program. S. Kiran PGT(Comp. Science), KV, Malleswaram

Functions exhibit the feature of MODULARITY in OOP (Object Oriented programming). What is Modularity? The act of breaking up larger programs into smaller unit is called modularity. S. Kiran PGT(Comp. Science), KV, Malleswaram

Advantages of using Functions Easier to maintain, update and debug. Enhances readability of the program Reusability of code S. Kiran PGT(Comp. Science), KV, Malleswaram

TYPES OF FUNCTIONS BUILT – IN FUNCTIONS USER DEFINED FUNCTIONS S. Kiran PGT(Comp. Science), KV, Malleswaram

BUILT – IN FUNCTIONS These are part of the compiler package, which are defined in the standard library files also called header files. For e.g.., string.h header file contains definition for the following functions. strlen(), strcmp(), strrev () etc. S. Kiran PGT(Comp. Science), KV, Malleswaram

USER DEFINED FUNCTIONS Are functions defined by the programmer. That is YOU. S. Kiran PGT(Comp. Science), KV, Malleswaram

FUNCTION DEFINITION A function must be defined before it is used anywhere in the program. Three important things that must be remembered 1. Function prototype 2. Function call 3. Function Definition S. Kiran PGT(Comp. Science), KV, Malleswaram

FUNCTION PROTOTYPE It has the following parts 1. Return type 2. Function Name 3. Parameters or Argument list For e.g.: int sum ( int x, int y) ; Return type Name Argument List Function prototype must end with a semi colon S. Kiran PGT(Comp. Science), KV, Malleswaram

FUNCTION DEFINITION AND CALL #include int square ( int n) #include { void main()return n x n; {} clrscr(); int square(int); int a, s; cout<<“Enter value for a”; cin>>a; s = square(a); cout<<“Square of given no. is”<<s; getch(); } S. Kiran PGT(Comp. Science), KV, Malleswaram prototype Func. call Function definition

S. Kiran PGT(Comp. Science), KV, Malleswaram

Note: A function prototype is not required if the function definition appears before its calling function Program Program S. Kiran PGT(Comp. Science), KV, Malleswaram

RECAPITULATION S. Kiran PGT(Comp. Science), KV, Malleswaram

Which feature of OOP does function exhibit? List the advantages of using functions? Name the different types of functions. Three things to remember in a function ______ What does function prototype tell the compiler? What is meant by return type? S. Kiran PGT(Comp. Science), KV, Malleswaram