0
0
Cprogramming~20 mins

Reusability and maintenance - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Reusability and Maintenance
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Modular Function Calls

What is the output of this C program that uses a reusable function to calculate the square of a number?

C
#include <stdio.h>

int square(int x) {
    return x * x;
}

int main() {
    int a = 3, b = 4;
    printf("%d %d\n", square(a), square(b));
    return 0;
}
A9 16
B3 4
C6 8
D12 16
Attempts:
2 left
💡 Hint

Remember the function returns the square of the input.

Predict Output
intermediate
2:00remaining
Output of Code Using Header File Inclusion

Given the following files, what will be the output when compiled and run?

math_ops.h
int add(int x, int y);

math_ops.c
int add(int x, int y) { return x + y; }

main.c
#include
#include "math_ops.h"
int main() {
printf("%d\n", add(5, 7));
return 0;
}

ARuntime error
B57
C12
DCompiler error due to missing function definition
Attempts:
2 left
💡 Hint

Check if the function is properly declared and defined.

🔧 Debug
advanced
2:00remaining
Identify the Cause of Unexpected Output

What causes the unexpected output in this C program that tries to reuse a function to increment a value?

#include <stdio.h>

void increment(int x) {
    x = x + 1;
}

int main() {
    int a = 5;
    increment(a);
    printf("%d\n", a);
    return 0;
}
AThe printf statement has wrong format specifier
BThe function is missing a return statement
CThe variable 'a' is not initialized
DThe function increments a copy of the variable, not the original
Attempts:
2 left
💡 Hint

Think about how arguments are passed to functions in C.

📝 Syntax
advanced
2:00remaining
Identify the Syntax Error in Modular Code

Which option contains the syntax error that prevents this modular C code from compiling?

#include <stdio.h>

int multiply(int x, int y) {
    return x * y
}

int main() {
    printf("%d\n", multiply(3, 4));
    return 0;
}
AMissing semicolon after return statement in multiply function
BMissing return type for multiply function
CMissing parentheses in printf call
DMissing main function return statement
Attempts:
2 left
💡 Hint

Check punctuation carefully in function bodies.

🚀 Application
expert
2:00remaining
Number of Functions in a Modular Program

Consider a C program split into three files: main.c, utils.c, and math.c. utils.c has 4 functions, math.c has 3 functions, and main.c has 2 functions. How many functions are available for reuse across the entire program after linking?

A3
B9
C7
D2
Attempts:
2 left
💡 Hint

Count all functions defined in all files.