💻 Unit 5 – Part A (2-Mark Q&A)

Programming in C

⬅ Back to Unit 5

Ad Space

Part A: Files and Preprocessor Directives

33. What is meant by command line argument?

Command-line arguments are values (strings) passed to a C program when it is executed from the command line or terminal. They are accessed in the main() function using the argc (argument count) and argv (argument vector) parameters.

34. How do you open a file in C for reading and writing?

You can open an existing file for both reading and writing using the "r+" mode with the fopen() function. If the file doesn't exist, it will return NULL.

Example: FILE *fp = fopen("data.txt", "r+");

35. Why preprocessor directives are used?

Preprocessor directives are instructions to the C preprocessor (which runs before the actual compiler). They are used for:

36. What does argc and argv indicate in command-line arguments?

37. Brief about single line comment with example.

A single-line comment is used to add explanatory notes to the code, which are ignored by the compiler. In C (from C99 standard), it starts with // and continues to the end of the line.

Example:

int x = 10; // This is a single-line comment initializing x.

38. How to open a file and close a file in C language?

39. What is meant by command line argument?

This is a duplicate of question 33. Command-line arguments are parameters supplied to a program when it is invoked from the command line. They provide a way to pass data into the program at runtime.

40. Compare the fseek() with ftell ().

Ad Space