0
0
Cprogramming~20 mins

Why modular programming is needed in C - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modular Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use modular programming in C?

Which of the following is the main reason to use modular programming in C?

ATo make the program run faster by using fewer CPU cycles
BTo write all code in a single file for simplicity
CTo avoid using variables and functions altogether
DTo organize code into separate parts that are easier to understand and maintain
Attempts:
2 left
💡 Hint

Think about how breaking a big task into smaller pieces helps in real life.

Predict Output
intermediate
2:00remaining
Output of modular code with separate functions

What is the output of this C program?

C
#include <stdio.h>

void greet() {
    printf("Hello, ");
}

void name() {
    printf("World!\n");
}

int main() {
    greet();
    name();
    return 0;
}
AHello,World!
BHello, World!
CHello World!
D
Hello
World!
Attempts:
2 left
💡 Hint

Look carefully at the spaces and newline characters in the print statements.

🔧 Debug
advanced
2:00remaining
Identify the error in modular code

What error will this C code produce?

C
#include <stdio.h>

void printMessage();

int main() {
    printMessage();
    return 0;
}

void printMessage() {
    printf("Modular programming is useful\n");
}
ALinker error: undefined reference to printMessage
BSyntax error: missing semicolon after function declaration
CNo error, program runs and prints the message
DRuntime error: segmentation fault
Attempts:
2 left
💡 Hint

Check if the function is declared and defined properly.

📝 Syntax
advanced
2:00remaining
Correct syntax for splitting code into modules

Which option shows the correct way to declare and define a function in separate files for modular programming?

AIn header file: <code>void greet();</code> In source file: <code>void greet() { printf("Hi\n"); }</code>
BIn header file: <code>void greet() { printf("Hi\n"); }</code> In source file: <code>void greet();</code>
CIn header file: <code>void greet() { printf("Hi\n"); }</code> In source file: <code>void greet() { printf("Hi\n"); }</code>
DIn header file: <code>void greet;</code> In source file: <code>void greet() { printf("Hi\n"); }</code>
Attempts:
2 left
💡 Hint

Think about what belongs in a header file versus a source file.

🚀 Application
expert
2:00remaining
Number of modules needed for a program

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?

AThree modules: one for input, one for processing, one for output
BTwo modules: one for input and output, one for processing
CFour modules: one for input, one for processing, one for output, one for main function
DOne module containing all code
Attempts:
2 left
💡 Hint

Think about separating different tasks into clear parts.