Docsity

Structured programming in C, Papers of C programming

Toggle sidebar
bg1
STRUCTURED PROGRAMMING
Structured programming involves the dividing of a very large program into
several small modules in such a way that each module is more manageable.
The usual design principle used is called top-down design. In top-down design,
the program is divided into a main module and its related modules. Each module is in
turn divided into submodules until the resulting modules are implicitly understood
without further division. (Forouzan and Gilberg 1997)
In C, this process can be done through the use of functions.
Already, programs that have been worked on involve one or more functions, one
of which is main. Every program always starts with main but it can call other functions.
So far, predefined functions have already been used. An example of which is the printf
function. It is known that the use of printf is to print strings to the screen but it is not
necessary for us to know how it is done.
Another type of function is user-defined functions. These are functions that are
created by the programmer.
Using functions:
A function must be both declared and defined. Declaration is done with a
prototype statement. The function is used by “calling” it. To call a function, the name of
the function is mentioned at main. The function definition contains the code of the
function.
The body that calls the function will be called the calling body.
Format of defining a function:
return_data_type function_name (parameter list)
{
<local declaration of variables>
statements;
.
.
.
<optional: return value>
}
The return data type is the data type of whatever value is to be returned to the
calling body. Usually there is only one value that can be returned to the calling body.
The parameter list is a list of variables that will accept values from the calling
body. Several values can be obtained from the calling body.
Variables can be declared within the function definition. Since these variables are
declared within the function, they are usable to the function only and are not recognized
outside of the function.

Partial preview of the text

Download Structured programming in C and more Papers C programming in PDF only on Docsity!

STRUCTURED PROGRAMMING

Structured programming involves the dividing of a very large program into several small modules in such a way that each module is more manageable.

The usual design principle used is called top-down design. In top-down design, the program is divided into a main module and its related modules. Each module is in turn divided into submodules until the resulting modules are implicitly understood without further division. (Forouzan and Gilberg 1997)

In C, this process can be done through the use of functions.

Already, programs that have been worked on involve one or more functions, one of which is main. Every program always starts with main but it can call other functions. So far, predefined functions have already been used. An example of which is the printf function. It is known that the use of printf is to print strings to the screen but it is not necessary for us to know how it is done.

Another type of function is user-defined functions. These are functions that are created by the programmer.

Using functions: A function must be both declared and defined. Declaration is done with a prototype statement. The function is used by “calling” it. To call a function, the name of the function is mentioned at main. The function definition contains the code of the function. The body that calls the function will be called the calling body.

Format of defining a function:

return_data_type function_name (parameter list) { statements; . . . <optional: return value> }

The return data type is the data type of whatever value is to be returned to the calling body. Usually there is only one value that can be returned to the calling body. The parameter list is a list of variables that will accept values from the calling body. Several values can be obtained from the calling body. Variables can be declared within the function definition. Since these variables are declared within the function, they are usable to the function only and are not recognized outside of the function.