File Input Output - Study Mode
[#286] What will be the output of the following C code? #include <stdio.h>
void main()
{
int n
scanf("%d", n)
printf("%d", n)
}
Correct Answer
(C) Nothing
[#287] What will be the output of the following C code? #include <stdio.h>
int main()
{
short int i
scanf("%h*d", &i)
printf("%hd", i)
return 0
}
Correct Answer
(A) Compilation error
[#288] The given statement FILE *fptr
Correct Answer
(A) Defines a pointer to the pre-defined structure type FILE
Explanation
Solution: FILE is a pre-defined structure.
[#289] What are the two predefined FILE pointers in C?
Correct Answer
(C) stdout and stderr
Explanation
Solution: Besides the file pointers which we explicitly open by calling fopen, there are also three predefined streams. stdin is a constant file pointer corresponding to standard input, and stdout is a constant file pointer corresponding to standard output. Both of these can be used anywhere when a file pointer is called for
for example, getchar() is the same as getc(stdin) and putchar(c) is the same as putc(c, stdout). The third predefined stream is stderr. Like stdout, stderr is typically connected to the screen by default. The difference is that stderr is not redirected when the standard output is redirected.
[#290] Which one of the following is valid for opening a read-only ASCII file?
Correct Answer
fileOpen(filename, "r")