Function Design Pattern

Raheelanjum
2 min readJust now

No matter what the purpose of a function is, the "syntax" for defining it is always the same. A design pattern is presented below to show this syntax. Your job is to memorize this design pattern, but until you do, you can cut and paste it from here.

Function Design Pattern

All functions in C always use the same basic pattern (syntax). This syntax can be captured in a "Design Pattern." Your job is to memorize this pattern for future use (and tests). When learning, you can refer here for help.

The Basic DP

All C functions will be written following the below "pattern.".

Above the word TYPE (or RETURN_TYPE) are one of the basic data types in C, including numbers (int, float, or double), bools, chars, arrays, and structures. RETURN_TYPE can be any of these except arrays.

Parts of the Function Design Pattern

Again, a function declaration is always of the form:

RETURN_TYPE - char, bool, int, float, void, or a structure type.

name - a symbolic name telling the user of the function the purpose of the function. In the case above, the name is average.

TYPE parameter, TYPE parameter, etc. - symbolic names for the inputs to the function (the data the function will process to compute an answer). The TYPE must be pre-specified for all C parameters.

--

--

Raheelanjum
Raheelanjum

Written by Raheelanjum

Highly skilled and experienced content writer dedicated to crafting compelling, informative content that resonates with diverse audiences. Expertise spans blog

No responses yet