9 - ICS 103: Computer Programming in C Handout9 Topic:...

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

View Full Document Right Arrow Icon
ICS 103: Computer Programming in C Handout-9  Topic: Function with Input Parameter. Objective: To know what is Function and what is the need of function. To know general form of Function Definition. To know about Function Prototype and its importance. To learn how to write user defined functions with input parameter . To know use of void in function. To know about actual and formal parameters of function. To know about different forms of return statements and their uses. What is Function? : Functions are the building blocks of any C program. In fact, a C program is a collection of functions e . g main ( ) , scanf( ), printf( ), sqrt(x), pow(x,y)…… sin(x), cos(x) etc. Functions are two types one is User defined and another is Standard Functions. Why are functions needed? : Dividing a large program into functions improves the understanding of the problem. Makes programs easy to correct and easy to maintain A function can be executed (called) from several locations in a program. It is not necessary to know the internal code of a function in order to be able to use it. For example, we do not know the code for the function printf(), but we know how to use it. Reuse of function subprograms. Function definition (writing the function code) : The general form for function definition is : Page 1 of 10
Background image of page 1

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

View Full DocumentRight Arrow Icon
Function type ( or function return type ) is the type of data item that is returned to the caller, such as in , double , …etc. Function name: (or function identifier) is the name of the function. The same rules for the variable names(identifiers) are applied to function names. Functions are identified and are called(referred to ) by their names. Parameter list : specifies the type of data items passed to the function. The data types are placed between parentheses, and if there is more than one item, they are separated by commas. Function prototype (declaring a function): Like variables, functions must be declared before they are used. The function prototype serves as a function declaration. The general form for function declarations ( function prototype is) : double large(double x1, double x2, char y); For Example : int sum ( int , int); declares a function called sum with a parameter list that consists of two int type data items. That is sum() expects two int type data items when it is called, and returns a int type data item to the caller. Specifying a name for each of the items in the parameter list is optional, but highly recommended. e . g
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

9 - ICS 103: Computer Programming in C Handout9 Topic:...

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

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