9 - ICS 103 Computer Programming in C Handout9 Topic Function with Input Parameter Objective To know what is Function and what is the need of function

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

This preview shows page 1 - 3 out of 10 pages.

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
Image of page 1
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.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 10 pages?

  • Spring '10
  • zaman
  • Subroutine, Return statement, Control flow, User defined function

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes