C-Command Line Arguments Questions and Answers
Command line arguments in C allow passing values to a program at runtime through the main() function parameters argc and argv. This feature is essential for flexible and interactive program execution. Many programming questions and answers in coding interviews test this concept through practical applications and debugging scenarios. This section provides C command line argument questions with answers and explanations, helping learners strengthen their understanding of runtime input handling. These examples are useful for TCS, Tech Mahindra, and Wipro placement exams where efficiency and clarity of coding are tested.
C-Command Line Arguments
Showing 10 of
129 questions
41. State the correct statement
- fclose() don't flush any unwritten data for the associated file.
- it is good practice to explicity use fclose() to close files that you have opened.
- fopen() automatically creates the bufer area in memory.
- Both b & c.
42. fclose () don't flush any unwritten data for the associated file.
- 13
- 26
- 27
- None of these
43. Find the output #include"stdio.h" void main ( ) { FILE *p; char *ch; ch="Welcome to puri"; p=fopen(raja.txt",'w"); fprintf(p, "%s",ch); fclose(p); p=fopen("raja.txt","r"); fflush(p); fscanf(p,"%s",ch); printf("%s",ch); }
- Welcome
- Welcome to puri
- Compilation error
- No output
44. If the file name is aaa and type from the command prompt aaa xxx yyy zzz then the following program prints xxx yyy and zzz. Which of the following option is true. #jinclude <stdio.h> int main (int argc, char *argv[]) { int x; printf(%d\n", argc); for (x=; x<argc; x++) printf(%s\n", argv[x]); return 0; }
- xxx is the 1st command line argument and yyy would be the second command line argument
- aaa is the 1st command line argument
- aaa xx yyy zzz is the 1st command line argument
- None of the above
45. Tthe contents of a file will be lost if it is opened in
- a mode
- a- mode
- w+ mode
- a+ mode
46. Which of the following command is used to access file randomly ?
- ftell()
- fseek()
- fgets()
- None of these
47. A stream can be thougght of as
- A system call
- A library function
- Both a and b
- A source or sink of data associated with disk or their devicesd
48. State the correct statement.
- fgets() read a line of string from a keyboard.
- gets () read a line of string from a file.
- fgets() takes two arguments.
- None of these
49. The function ftell(fp) returns
- the beginning position of the file represented by fp.
- the end position o the file represented by fp.
- The current position of the file represented by fp.
- None of these
50. The function ftell(fp) returns
- The beginning position of the file reresented by fp.
- The end position of the file represented by fp
- the current position of the file represented by fp.
- None of these