0
0
Cprogramming~10 mins

main function and program entry - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main function in C.

C
int [1]() {
    return 0;
}
Drag options to blanks, or click blank then click option'
Amain
Bstart
Cbegin
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name other than 'main' for the program entry point.
Forgetting to specify the return type as int.
2fill in blank
medium

Complete the code to print "Hello, World!" inside the main function.

C
#include <stdio.h>

int main() {
    [1]("Hello, World!\n");
    return 0;
}
Drag options to blanks, or click blank then click option'
Aprint
Bprintln
Cecho
Dprintf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a C function.
Using 'echo' or 'println' which are not valid in C.
3fill in blank
hard

Fix the error in the main function declaration to make it valid C code.

C
int [1](void) {
    return 0;
}
Drag options to blanks, or click blank then click option'
Aprogram
Bmain
Cstart
Dentry
Attempts:
3 left
💡 Hint
Common Mistakes
Using other function names like 'start' or 'entry' instead of 'main'.
4fill in blank
hard

Fill both blanks to complete the main function that prints a number.

C
#include <stdio.h>

int [1]() {
    int num = 5;
    [2]("Number: %d\n", num);
    return 0;
}
Drag options to blanks, or click blank then click option'
Amain
Bprint
Cprintf
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of 'printf'.
Naming the function other than 'main'.
5fill in blank
hard

Fill all three blanks to complete a main function that prints a message and returns success.

C
#include <stdio.h>

int [1]() {
    [2]("Welcome to C programming!\n");
    return [3];
}
Drag options to blanks, or click blank then click option'
Amain
Bprintf
C0
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a non-zero value to indicate success.
Using a function name other than 'main'.