Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Function Ordering and Function Prototypes - Lecture Slides | CSE A205, Study notes of Engineering

Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Fall 2008;

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-se8
koofers-user-se8 🇺🇸

5

(1)

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #9
Jeffrey Miller, Ph.D.
pf3
pf4
pf5

Partial preview of the text

Download Function Ordering and Function Prototypes - Lecture Slides | CSE A205 and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Function Ordering

When we define and implement a function at the sametime, the function definition (and thereforeimplementation) must be placed above the code that iscalling the function

This can be a problem for programmers because theplacement of the functions will then determine the order inwhich they are called

Although this is an inconvenience, we can write code thatconforms to this standard

The problem arises when we have two functions that calleach other

Function Prototypes

To provide a solution for the previous problem (and torelieve programmers from having to place functionimplementations above the calls to the functions), we havefunction prototypes

A function prototype is merely the function declaration,without the implementation

A function prototype consists of the return type, thefunction name, and the list of parameter types, followed bya semi-colon

It can optionally consist of the names of the parameters as well

(); int addOne(int);

Function Prototypes

Function prototypes are placed toward the top of a .c or .cpp file, after the#include statements and before the first function implementation

#include <stdio.h> int addOne(int); int add(int); int add(int value)

if (value

return addOne(value); } return value

} int addOne(int value)

if (value

return value

} return add(value); } void main()

add(11); }

Homework

Homework #4 is posted!