cp_1_Lect_40 - What is Function in C? Functions are central...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
5/10/10 11 What is Function in C? Functions are central to C programming and to the philosophy of C program design. A C program consists of one or more function definitions, including exactly one that must be called main A function is a named, independent section of C code that performs a specific task and optionally returns a value to the calling program.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 22 What is Function in C? A function is named : Each function has a unique name. By using that name in another part of the program, one can execute the statements contained in the function. This is known as calling the function. A function can be called from within another function. A function is independent: A function can perform its task without interference from or interfering with other parts of
Background image of page 2
5/10/10 33 What is Function in C? A function performs a specific task: Such as sending a line of text to a printer, sorting an array into numerical order or calculating a cube root. A function can return a value to the calling program: When a program calls a function, the statements it contains are executed. If you
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 44 /* Function: maxi * Purpose : Find the maximum of its integer * arguments * Inputs : Two parameters * Returns : The maximum of parameters * Modifies: Nothing * Error checking: None */ #include<stdio.h> i nt maxi(int, int);
Background image of page 4
5/10/10 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 66
Background image of page 6
5/10/10 77 Function Declaration and Definition A declaration merely provides a function prototype. Function header : Includes the return type and the list of parameters Syntax: return_type function_name ( arg-typ name-1 ,..., arg-typ name-n ); Example:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 88 Function Declaration and The definition of a function includes both the function prototype and the function body, i.e. its implementation. Syntax: return_typ function_name ( arg-typ name-1 ,..., arg-typ name-n ) { /* statements ; */ } Example:
Background image of page 8
5/10/10 99 Complete C Program Using long int cube(int); /* Function declaration */ int main() { long int c; c = cube( 5 ) ; /* Function call */ printf(“Cube of 5 = %ld”,c); return; } long int cube( int num ) Actual parameter Formal parameter
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 1010 Function Parameters There are two types of function parameters: Formal parameters: Appear in a declaration or a definition of a function. Actual parameters: Appear in a call to the function.
Background image of page 10
1111 Passing Arguments to a Function(1) Pass by value : Single value is passed to a function via an actual argument. The value of actual argument is copied
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 46

cp_1_Lect_40 - What is Function in C? Functions are central...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online