1. Computing & Technology

Discuss in my forum

C Tutorial - Lesson Six - About Functions

By , About.com Guide

1 of 6

Learn About Functions
We've briefly used functions before; strcpy() was used to assign a string. If you've used a spreadsheet worksheet function before then you'll have a good idea what a function is like. It's a block of code that can be called from anywhere in your application. It performs some calculation or process and then returns a value.

Every single example program you've seen so far is actually a function. It's called main() and it returns an integer. The difference is that it's called by the operating system when your application is loaded into RAM.

There are two types of functions. The ones that are provided with the compiler and the ones that you write. Let's look at the functions provided with the compiler.

Built In Functions

Ansi C specifies 15 include files that compiler writers must implement for the C standard library. They are listed below.
  • <assert.h> *Diagnostics
  • <ctype.h> *Character Class Tests
  • <errno.h> Error Codes Reported by Library Functions
  • <float.h> Floating-Point Limits
  • <limits.h> Implementation-defined Limits
  • <locale.h> Locale-specific Information
  • <math.h> *Mathematical Functions
  • <setjmp.h> Non-local Jumps
  • <signal.h> Signals
  • <stdarg.h> *Variable Argument Lists
  • <stddef.h> Definitions of General Use
  • <stdio.h> *Input and Output
  • <stdlib.h> *Utility functions
  • <string.h> *String functions
  • <time.h> *Time and Date functions
      * Are the ones I consider most useful.

      On the next Page : Learn how to call functions.

©2012 About.com. All rights reserved.

A part of The New York Times Company.