HP C A.06.05 Reference Manual
Program Organization
Structuring a C Program
Chapter 230
Structuring a C Program
When you write a C program, you can put all of your source code into one file or spread it
across many files. A typical C source file contains some or all of the following components:
• Preprocessor directives
• Variables
• Functions
Example 2-1 Example
The following shows how a program can be organized:
/* preprocessor directives */
#include <stdio.h>
#define WEIGHTING_FACTOR 0.6
/* global typedef declaration */
typedef float THIRTY_TWO_BIT_REAL;
/* global variable declaration */
THIRTY_TWO_BIT_REAL correction_factor = 1.15;
/* prototype */
float average (float arg1, THIRTY_TWO_BIT_REAL arg2);
/* start of function body */
{
/* local variable declaration */
float mean;
/* assignment statement */
mean = (arg1 * WEIGHTING_FACTOR) + (arg2 * (1.0 - WEIGHTING_FACTOR));
/* return statement */
return (mean * correction_factor);
/* end of function body */
}
int main(void)