Bird
0
0

You want to write a C program that accepts command-line arguments. Which is the correct main function signature to access them?

hard📝 Application Q8 of 15
C - Basics and Execution Environment
You want to write a C program that accepts command-line arguments. Which is the correct main function signature to access them?
Aint main(void)
Bvoid main(int argc, char *argv[])
Cint main(int argc, char *argv[])
Dint main(char argv[], int argc)
Step-by-Step Solution
Solution:
  1. Step 1: Understand command-line argument parameters

    To access command-line arguments, main must accept two parameters: argument count and argument vector.
  2. Step 2: Identify correct parameter order and types

    The correct signature is int main(int argc, char *argv[]). Others have wrong order, types, or return type.
  3. Final Answer:

    int main(int argc, char *argv[]) -> Option C
  4. Quick Check:

    Command-line main signature = int main(int argc, char *argv[]) [OK]
Quick Trick: Use int main(int argc, char *argv[]) for command-line args [OK]
Common Mistakes:
  • Using void return type
  • Swapping argc and argv
  • Wrong parameter types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes