Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Functions

Node:Functions, Next:, Previous:The form of a C program, Up:Top



Functions

Solving problems and getting results.

A function is a section of program code that performs a particular task. Making functions is a way of isolating one section of code from other independent sections. Functions allow a programmer to separate code by its purpose, and make a section of code reusable -- that is, make it so the section can be called in many different contexts.

Functions should be written in the following form:

type function_name (type parameter1_name, type parameter2_name, ...)

{
  variable declarations

  statements
  ...
  ...
  ...
}

You may notice when reading the examples in this chapter that this format is somewhat different from the one we have used so far. This format conforms to the ANSI Standard and is better C. The other way is old-fashioned C, although GCC will still compile it. Nevertheless, GCC is not guaranteed to do so in the future, and we will use ANSI Standard C in this text from now on.

As shown above, a function can have a number of parameters, or pieces of information from outside, and the function's body consists of a number of declarations and statements, enclosed by curly brackets: {...}.

 
 
  Published under free license. Design by Interspire