C Programming MCQ Hardest Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Sandesh
S
Sandesh
Community Contributor
Quizzes Created: 1 | Total Attempts: 942
Questions: 10 | Attempts: 942

SettingsSettingsSettings
C Programming MCQ Hardest Trivia Quiz - Quiz

.


Questions and Answers
  • 1. 

    In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?

    • A.

      "I am a boy\r\n\0"

    • B.

      "I am a boy\r\0"

    • C.

      "I am a boy\n\0"

    • D.

      "I am a boy"

    Correct Answer
    C. "I am a boy\n\0"
    Explanation
    The correct answer is "I am a boy\0". When the line "I am a boy\r" is read into the array using fgets(), it will include the carriage return character '\r' at the end of the string. The '\r' represents a carriage return, which is a control character used to move the cursor to the beginning of the line. The '\0' represents the null character, which is used to terminate the string. Therefore, the resulting string in the array will be "I am a boy\0".

    Rate this question:

  • 2. 

    What is the purpose of "rb" in fopen() function used below in the code?

    • A.

      Open "source.txt" in binary mode for reading

    • B.

      Open "source.txt" in binary mode for reading and writing

    • C.

      Create a new file "source.txt" for reading and writing

    • D.

      None of above

    Correct Answer
    A. Open "source.txt" in binary mode for reading
    Explanation
    The purpose of "rb" in the fopen() function is to open the file "source.txt" in binary mode for reading. The "b" in "rb" indicates that the file should be opened in binary mode, which means that the file will be read as a sequence of bytes rather than as text. This is useful when working with files that contain non-textual data, such as images or audio files.

    Rate this question:

  • 3. 

    Which of the following operations can be performed on the file "NOTES.TXT" using the below code?

    • A.

      Reading

    • B.

      Writing

    • C.

      Appending

    • D.

      Read and Write

    Correct Answer
    D. Read and Write
    Explanation
    The code provided does not explicitly mention any specific operation being performed on the file "NOTES.TXT". However, the code suggests that it is capable of both reading and writing to the file. Therefore, the correct answer is "Read and Write".

    Rate this question:

  • 4. 

    What does fp point to in the program ?

    • A.

      The first character in the file

    • B.

      A structure which contains a char pointer which points to the first character of a file.

    • C.

      The name of the file.

    • D.

      The last character in the file.

    Correct Answer
    B. A structure which contains a char pointer which points to the first character of a file.
    Explanation
    The correct answer is a structure which contains a char pointer which points to the first character of a file. This is because in most programming languages, when we open a file, we use a file pointer (fp) to keep track of the file's location. The file pointer is a structure that contains information about the file, including a char pointer that points to the first character in the file. Therefore, fp points to a structure which contains a char pointer pointing to the first character of the file.

    Rate this question:

  • 5. 

    To print out a and b given below, which of the following printf() statement will you use?

    • A.

      Printf("%f %lf", a, b);

    • B.

      Printf("%Lf %f", a, b);

    • C.

      Printf("%Lf %Lf", a, b);

    • D.

      Printf("%f %Lf", a, b);

    Correct Answer
    A. Printf("%f %lf", a, b);
    Explanation
    The correct answer is printf("%f %lf", a, b) because it correctly specifies the format specifiers for the variables a and b. The %f specifier is used for float variables, while the %lf specifier is used for double variables. Therefore, this printf statement will correctly print out the values of a and b. The other printf statements either use incorrect format specifiers or mix up the order of the specifiers, which would result in incorrect output.

    Rate this question:

  • 6. 

    Which files will get closed through the fclose() in the following program?

    • A.

      "A.C" "B.C" "C.C"

    • B.

      "B.C" "C.C"

    • C.

      "A.C"

    • D.

      Error in fclose()

    Correct Answer
    D. Error in fclose()
    Explanation
    The correct answer is "Error in fclose()". This means that there is an error in the fclose() function in the program, and therefore no files will get closed.

    Rate this question:

  • 7. 

    On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?

    • A.

      R n

    • B.

      Trh

    • C.

      Err

    • D.

      None of above

    Correct Answer
    B. Trh
    Explanation
    The contents of the 'target.txt' file will be "Trh". This is because the program reads the source file and only writes the second and third characters of each line to the target file. In the given source line "To err is human", the second character is 'r' and the third character is 'r', so only "Trh" will be written to the target file.

    Rate this question:

  • 8. 

    To scan a and b given below, which of the following scanf() statement will you use?

    • A.

      Scanf("%f %f", &a, &b);

    • B.

      Scanf("%Lf %Lf", &a, &b);

    • C.

      Scanf("%f %Lf", &a, &b);

    • D.

      Scanf("%f %lf", &a, &b);

    Correct Answer
    D. Scanf("%f %lf", &a, &b);
    Explanation
    The correct answer is scanf("%f %lf", &a, &b); because the format specifier %f is used to scan a float value, and the format specifier %lf is used to scan a double value. Since the variables a and b are of type float and double respectively, this scanf statement is the correct one to use.

    Rate this question:

  • 9. 

    Out of fgets() and gets() which function is safe to use?

    • A.

      Gets()

    • B.

      Fgets()

    • C.

      Ggets()

    • D.

      Kgets()

    Correct Answer
    B. Fgets()
    Explanation
    fgets() is the safer function to use out of fgets() and gets(). The gets() function is considered unsafe because it does not perform any bounds checking on the input, which can lead to buffer overflow vulnerabilities. On the other hand, fgets() allows you to specify the maximum number of characters to read, preventing buffer overflow issues.

    Rate this question:

  • 10. 

    Consider the following program and what will be content of t?

    • A.

      Size of "DUMMY.C" file

    • B.

      The handle associated with "DUMMY.C" file

    • C.

      Garbage value

    • D.

      Error in fileno()

    Correct Answer
    B. The handle associated with "DUMMY.C" file
    Explanation
    The content of "t" will be the handle associated with the "DUMMY.C" file. This means that "t" will contain the identifier or reference to the file "DUMMY.C", allowing the program to perform operations on that file such as reading or writing data.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 12, 2016
    Quiz Created by
    Sandesh
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.