Which of the following functions is not declared in <stdio.h>?

2023

Which of the following functions is not declared in <stdio.h>?

  1. A.

    printf()

  2. B.

    scanf()

  3. C.

    fopen()

  4. D.

    sqrt()

  5. E.

    fprintf()

Attempted by 145 students.

Show answer & explanation

Correct answer: D

Concept

The C standard library groups its functions into headers by purpose. The <stdio.h> header declares the standard input/output routines — functions for formatted I/O, file-stream handling, and character/string streams. Mathematical routines such as square root, power and trigonometric functions are NOT I/O; they live in a separate header, <math.h>. To find the odd one out, classify each function by the header that declares it.

Application

Mapping each offered function to its declaring header:

Function

Declaring header

Role

printf()

<stdio.h>

formatted output to stdout

scanf()

<stdio.h>

formatted input from stdin

fopen()

<stdio.h>

open a file stream

fprintf()

<stdio.h>

formatted output to a stream

sqrt()

<math.h>

compute square root (math, not I/O)

Cross-check / Result

Four of the five — printf(), scanf(), fopen() and fprintf() — are I/O routines declared in <stdio.h>. Only sqrt() is a mathematical function; it is declared in <math.h> and requires linking the math library. Hence the function not declared in <stdio.h> is sqrt().

Explore the full course: Niacl Ao It Specialist

Loading lesson…