0
0
Cprogramming~20 mins

main function and program entry - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of C Program Entry
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this C program?

Consider the following C code. What will it print when run?

C
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
AHello World
Bhello, world!
CHello, World!
DCompilation error
Attempts:
2 left
💡 Hint

Look carefully at the exact string inside printf including capitalization and punctuation.

Predict Output
intermediate
2:00remaining
What is the value of variable x after running this program?

What value does x hold after the program finishes?

C
#include <stdio.h>

int main() {
    int x = 5;
    x = x + 10;
    return 0;
}
A15
B5
C10
DCompilation error
Attempts:
2 left
💡 Hint

Remember that x = x + 10; adds 10 to the current value of x.

Predict Output
advanced
2:00remaining
What is the output of this program with command line arguments?

What will this program print if run with the command ./program 3 7?

C
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Not enough arguments\n");
        return 1;
    }
    int a = atoi(argv[1]);
    int b = atoi(argv[2]);
    printf("Sum: %d\n", a + b);
    return 0;
}
ASum: 10
BSum: 37
CNot enough arguments
DRuntime error
Attempts:
2 left
💡 Hint

Check how argc and argv are used to get command line arguments and convert them to integers.

Predict Output
advanced
2:00remaining
What error does this program produce when compiled?

What error will the compiler show for this program?

C
#include <stdio.h>

void main() {
    printf("Hello\n");
}
ASyntax error: missing semicolon
BWarning: return type of 'main' is not 'int'
CNo error, program runs fine
DLinker error: undefined reference to 'main'
Attempts:
2 left
💡 Hint

Check the return type of the main function in standard C.

🧠 Conceptual
expert
2:00remaining
How many times is the main function called in a standard C program execution?

In a typical C program, how many times is the main function called during the program's lifetime?

ADepends on the number of threads created
BMultiple times, each time a function calls it
CZero times, the OS runs the program without calling main
DExactly once, when the program starts
Attempts:
2 left
💡 Hint

Think about the role of main as the program's entry point.