Difficulty: Easy
Correct Answer: sample
Explanation:
Introduction / Context: The item checks the layout of command-line arguments in C and how argc and argv relate. Specifically, argv[0] conventionally stores the program name (or path), and argc is the count of items in argv.
Given Data / Assumptions:
Concept / Approach: When the program is launched with no additional arguments, argc is 1 and argv points to an array of length 1 plus the terminating NULL. Therefore, argc - 1 equals 0, and the expression prints the string stored at argv[0], i.e., the program name path or name.
Step-by-Step Solution:
argc = 1 because there are no user arguments. argv[0] = "sample" (implementation may include a path, but the question assumes just the name). argv[argc - 1] = argv[0] = "sample".Verification / Alternative check: Add a second argument (e.g., sample X); now argc=2 and argv[argc - 1] = argv[1] = "X". The logic matches across cases.
Why Other Options Are Wrong:
Common Pitfalls: Forgetting that argv[0] is occupied by the program name; users sometimes assume argv[0] is the first user argument, which is incorrect.
Final Answer: sample
Discussion & Comments