Which of the following is the main reason to use modular programming in C?
Think about how breaking a big task into smaller pieces helps in real life.
Modular programming helps by dividing code into smaller, manageable parts. This makes it easier to read, fix, and reuse code.
What is the output of this C program?
#include <stdio.h> void greet() { printf("Hello, "); } void name() { printf("World!\n"); } int main() { greet(); name(); return 0; }
Look carefully at the spaces and newline characters in the print statements.
The greet function prints "Hello, " with a space and no newline. The name function prints "World!" with a newline. Together they print "Hello, World!" on one line.
What error will this C code produce?
#include <stdio.h> void printMessage(); int main() { printMessage(); return 0; } void printMessage() { printf("Modular programming is useful\n"); }
Check if the function is declared and defined properly.
The function printMessage is declared before main and defined after main. This is valid in C, so the program runs without error and prints the message.
Which option shows the correct way to declare and define a function in separate files for modular programming?
Think about what belongs in a header file versus a source file.
The header file should only declare the function prototype (no body). The source file defines the function with its body.
You are writing a C program that reads user input, processes data, and prints results. To follow modular programming principles, how many separate modules should you create at minimum?
Think about separating different tasks into clear parts.
Separating input, processing, and output into three modules makes the program easier to maintain and understand. The main function can be part of one of these or separate, but minimum three modules are best practice.