wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

EOF is an integer type defined in stdio.h and has a value ______

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

What is the output of the following C code if there is no error in stream fp?

  1. #include <stdio.h>

  2. int main()

  3. {

  4. FILE *fp;

  5. fp = fopen("newfile", "w");

  6. printf("%d\n", ferror(fp));

  7. return 0;

  8. }

a)

Compilation error

b)

0

c)

1

d)

Any nonzero value

2.

Within main, return expr statement is equivalent to ________

a)

abort(expr)

b)

exit(expr)

c)

ferror(expr)

d)

none of the mentioned

3.

What will be the output of the following C code? (Assuming the newfile1.txt exists)

  1. #include <stdio.h>

  2. int main()

  3. {

  4. FILE *fp;

  5. char c;

  6. int n = 0;

  7. fp = fopen("newfile1.txt", "r");

  8. while (!feof(fp))

  9. {

  10. c = getc(fp);

  11. putc(c, stdout);

  12. }

  13. }

a)

Compilation error

b)

Prints to the screen content of newfile1.txt completely

c)

Prints to the screen some contents of newfile1.txt

d)

None of the mentioned

4.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. int main()

  3. {

  4. FILE *fp = stdout;

  5. stderr = fp;

  6. fprintf(stderr, "%s", "hello");

  7. }

a)

Compilation error

b)

hello

c)

Undefined behaviour

d)

Depends on the standard

5.

What will be the output of the following C code?

  1. #include <stdio.h>

  2. int main()

  3. {

  4. char buf[12];

  5. stderr = stdin;

  6. fscanf(stderr, "%s", buf);

  7. printf("%s\n", buf);

  8. }

a)

Compilation error

b)

Undefined behaviour

c)

Whatever user types

d)

None of the mentioned

6.

stderr is similar to?

a)

stdin

b)

stdout

c)

both stdout and stdin

d)

none of the mentioned

7.

What happens when we use the following C statement?

fprintf(stderr, "error: could not open filen");

a)

The diagnostic output is directly displayed in the output

b)

The diagnostic output is pipelined to the output file

c)

The line which caused error is compiled again

d)

The program is immediately aborted

8.

Which of the following function can be used to terminate the main function from another function safely?

a)

return(expr);

b)

exit(expr);

c)

abort();

d)

both exit(expr); and abort();

9.

Which one of the following is correct syntax for opening a file.

a)

FILE fopen(const filename, const char *mode)

b)

FILE fopen(const filename)

c)

FILE open(const filename, const char *mode)

d)

FILE open(const*filename)

10.

What is the function of the mode ‘ w+’?

a)

create text file for writing, discard previous contents if any

b)

create text file for update, discard previous contents if any

c)

create text file for writing, do not discard previous contents if any

d)

create text file for update, do not discard previous contents if any

11.

If the mode includes b after the initial letter, what does it indicates?

a)

text file

b)

big text file

c)

binary file

d)

blueprint text

12.

fflush(NULL) flushes all------------------

a)

input streams

b)

output streams

c)

previous contents

d)

appended text

13.

_____removes the named file, so that a subsequent attempt to open it will fail.

a)

remove(const *filename)

b)

remove(filename)

c)

remove()

d)

fclose(filename)

14.

What does tmpfile() returns when it could not create the file?

a)

stream and NULL

b)

only stream

c)

only NULL

d)

does not return anything

15.

EOF is an integer type defined in stdio.h and has a value ____________

a)

1

b)

0

c)

NULL

d)

-1