| You are here: | About>Computing & Technology>C / C++ / C# |
![]() | C / C++ / C# |
Elsewhere on the WebC Tutorial - Lesson Six - About FunctionsCalling a Function and Writing Your Own FunctionsIn this example we'll call the function pow() in <math.h>. It calculates xy where both x and y are doubles and x is positive. Create a project called ex6_1 or load the sample project ex6_1.
#include <math.h> Writing FunctionsFunctions divide a program into smaller manageable chunks. It's usual to group related functions into libraries and then use a header file to make public those functions. That way, other parts of your application can call them.
Return TypeAll functions have a return type. If you omit it, then int is assumed. So you should always specify the return type.A function can return nothing- just like a procedure in pascal. In C this is done with the void type. E.g. void StartLogging() { Return ValueOther than in a void function, a value of the function's return type must be returned. This is done with the return statement. This also exits the function. For a void function, return by itself will do.//ex6_11This adds two numbers and outputs C= 13. On the next page : Learn about function parameters.
Elsewhere on the Web |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


