0
0
Cprogramming~10 mins

Syntax of command line arguments - Interactive Code Practice

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

Complete the code to declare the main function with command line arguments.

C
int main(int [1], char *argv[]) {
    return 0;
}
Drag options to blanks, or click blank then click option'
Aargc
Bargv
Cargc[]
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using argv as the first parameter name instead of argc.
Adding brackets to argc like argc[].
2fill in blank
medium

Complete the code to access the first command line argument (excluding program name).

C
printf("First argument: %s\n", [1][1]);
Drag options to blanks, or click blank then click option'
Aargv[]
Bargc
Cargs
Dargv
Attempts:
3 left
💡 Hint
Common Mistakes
Using argc instead of argv to access arguments.
Trying to access argv with brackets like argv[].
3fill in blank
hard

Fix the error in the main function declaration for command line arguments.

C
int main([1] argc, char *argv[]) {
    return 0;
}
Drag options to blanks, or click blank then click option'
Afloat
Bvoid
Cint
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using void or char instead of int for argc.
Omitting the type before argc.
4fill in blank
hard

Fill both blanks to declare main with command line arguments correctly.

C
int main([1] argc, [2] *argv[]) {
    return 0;
}
Drag options to blanks, or click blank then click option'
Aint
Bchar
Cfloat
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using float or void types.
Swapping the types of the parameters.
5fill in blank
hard

Fill all three blanks to print all command line arguments using a loop.

C
for (int [1] = 0; [2] < [3]; [1]++) {
    printf("Arg %d: %s\n", [1], argv[[1]]);
}
Drag options to blanks, or click blank then click option'
Ai
Bargc
Ccount
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Comparing to a variable other than argc.