IV.
LESSON PROPER
I. Introduction
Introduce the lesson by explaining the significance of structure in C programming. Highlight that
understanding the organization of a C program is essential for creating functional and efficient
code.
Objective: Students will understand the components that make up the structure of a C program,
including headers, declarations, functions, comments, identifiers, and reserved words.
II. Main Content
1. Headers
Definition: Headers are segments of a C program where libraries are included, and macros are
defined. They help the compiler understand the specific functionalities and definitions needed for
the program.
Preprocessor and Preprocessor Directives:
The preprocessor is a system program that modifies the C code before it's passed to the compiler.
A preprocessor directive is a line that starts with # and provides instructions to the preprocessor.
The two most common directives are:
#include: Used to include standard libraries or user-defined libraries into the program.
#define: Used to define constant macros that are replaced with their defined values before
compilation.
Example:
#define pi_value 3.1416
This line replaces every occurrence of pi_value with 3.1416 in the program before it's compiled.
Commonly Used Header Files:
alloc.h: Memory management functions.
conio.h: Functions related to console input/output.
ctype.h: Macros for character classification and conversion.
math.h: Mathematical functions.
stdio.h: Standard input/output operations.
string.h: String manipulation and memory handling functions.
2. Declarations
Definition: Declarations in C programs make known to the computer the variables, functions, or
objects that the program will use. This ensures that the required memory space is allocated for
each entity.
Example:
int a, b, sum;
This declares three integer variables a, b, and sum.
3. Functions
Definition: Functions are blocks of code designed to perform specific tasks. Every C program
must contain at least one function, which is the main() function. The main() function is the entry
point for program execution.
Example:
int main() {
printf("Hello, World!");
return 0;
}
Note: C is case-sensitive, so main() and Main() are not the same.
4. Comments
Definition: Comments are non-executable lines used for documentation purposes. They help in
improving program readability but are ignored by the compiler.
Types of Comments:
Multiple-line comments: Enclosed between /* and */.
Single-line comments: Denoted by //.
Example of Multiple-line Comment:
/* This is a multiple-line comment
It can span several lines */
Example of Single-line Comment:
// This is a single-line comment
5. Identifiers
Definition: Identifiers are names given to various elements in a C program, such as variables,
functions, and arrays. They must follow certain guidelines.
Guidelines for Identifiers:
Must consist of letters and digits, with the first character being a letter.
Uppercase and lowercase letters are permitted, but they are not interchangeable (C is case-
sensitive).
Special characters, except for the underscore (_), are not allowed.
Example:
int studentAge;
6. Reserved Words
Definition: Reserved words, or keywords, have predefined meanings in C. They cannot be used
as identifiers for variables, functions, or other user-defined elements.
Examples: int, return, if, while, for
III. Activity
Group Discussion:
Divide students into groups and ask them to discuss the importance of the structure of a C
program. They should highlight the role of headers, declarations, functions, comments, and
identifiers.
Encourage them to consider how proper structure impacts program readability, maintainability,
and error reduction.
Individual Exercise:
Have students write a short C program that demonstrates the use of headers, declarations,
functions, and comments. For example, a simple program that calculates the area of a circle
using the #define directive for pi.
Sample Exercise:
#include <stdio.h>
#define pi_value 3.1416
int main() {
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = pi_value * radius * radius;
printf("Area of the circle: %.2f\n", area);
return 0;
}
IV. Conclusion
Summary:
Recap the key components of a C program structure: headers, declarations, functions, comments,
identifiers, and reserved words.
Emphasize the importance of using a clear and well-organized structure to create programs that
are efficient and easy to maintain.
Takeaway:
A solid understanding of how to structure a C program is fundamental for efficient
programming. This knowledge forms the foundation for tackling more complex programming
challenges.