W13-Struct_Func1 - Functions 1 1 We've Already Use...

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

View Full Document Right Arrow Icon
10/24/05 1 Functions 1 10/24/05 2 We’ve Already Use Functions • int main(void) printf(arg1, arg2, …) scanf(arg1, arg2, …) • sqrt(arg1) • rand() • time(NULL) 10/24/05 3 What Is a Function? A request to: 1. Go to another part of your program (Function Call). 2. Perform a calculation or some other useful service (Function Execution). 3. Return and continue with the C code after the call (Function Return).
Image of page 1

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

View Full Document Right Arrow Icon
10/24/05 4 Three Ways to Use Functions x = function1(arg1, arg2); takes arguments, returns a value. function2(arg1,arg2); takes arguments, returns nothing. function3(); takes no arguments, returns nothing. Last two examples sometimes called subroutine (when nothing returned) 10/24/05 5 C Functions Three parts to writing functions 1 Declaration -- tell the compiler about the function (function prototype). 2 Definition -- write the code the function executes. 3 Call -- Call (use) the function to do some work. 10/24/05 6 Declaration - Function Prototype type function( parameter_list ); for example: double cube( double x); /* x is optional */ output value
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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