Exercise: Library Functions

Questions for: Library Functions

What is stderr ?
A:
standard error
B:
standard error types
C:
standard error streams
D:
standard error definitions
Answer: C
The standard error(stderr) stream is the default destination for error messages and other diagnostic warnings. Like stdout, it is usually also directed to the output device of the standard console (generally, the screen).
Which standard library function will you use to find the last occurance of a character in a string in C?
A:
strnchar()
B:
strchar()
C:
strrchar()
D:
strrchr()
Answer: D

strrchr() returns a pointer to the last occurrence of character in a string.

Example:


#include <stdio.h>
#include <string.h>

int main()
{
    char str[30] = "12345678910111213";
    printf("The last position of '2' is %d.\n",
            strrchr(str, '2') - str);
    return 0;
}

Output: The last position of '2' is 14.

Input/output function prototypes and macros are defined in which header file?
A:
conio.h
B:
stdlib.h
C:
stdio.h
D:
dos.h
Answer: C
stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.
What will the function rewind() do?
A:
Reposition the file pointer to a character reverse.
B:
Reposition the file pointer stream to end of file.
C:
Reposition the file pointer to begining of that line.
D:
Reposition the file pointer to begining of file.
Answer: D
rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file.
Example: rewind(FilePointer);
Ad Slot (Above Pagination)
Quiz