computer MCQs

12th • Chapter 14

46 Questions TextBook
1

What is a stream in C?

A
A physical device
B
A sequence of bytes
C
A logical interface to a file
D
A built-in C data type
2

Which function is used to open a file in C?

A
open()
B
file_open()
C
stream_open()
D
fopen()
3

What does the mode "w" signify when opening a file?

A
Read
B
Write
C
Append
D
Read and Write
4

If a file opened in "w" mode already exists, what happens to its contents?

A
Data is appended
B
An error occurs
C
Its contents are overwritten
D
The user is prompted
5

What does EOF stand for?

A
End of Function
B
End of File
C
End of Format
D
Error on File
6

Which header file contains the declarations for standard file handling functions?

A
string.h
B
conio.h
C
stdio.h
D
file.h
7

What is a file pointer?

A
A memory address of the file
B
A variable of type FILE
C
An integer representing the file size
D
A character in the file
8

Which symbol is used to declare a pointer variable in C?

A
&
B
#
C
*
D
$
9

The function to close a file is:

A
close()
B
file_close()
C
fclose()
D
end_file()
10

Which function is used to read a single character from a file?

A
readc()
B
getc()
C
fget()
D
getchar()
11

Which function is used to write a single character to a file?

A
putc()
B
writec()
C
fput()
D
putchar()
12

In C, a string is implemented as an:

A
Array of integers
B
Linked list of characters
C
Array of characters
D
A special data type
13

What character terminates every valid string in C?

A
Newline character (\n)
B
EOF character
C
Null character (\0)
D
A period (.)
14

Which function is used to copy a string to a string variable?

A
strcpy()
B
strcopy()
C
stringcopy()
D
copystr()
15

Which header file is required for using the strcpy() function?

A
stdio.h
B
stdlib.h
C
string.h
D
conio.h
16

The function fputs() writes a string to a file. What does it NOT write?

A
The string itself
B
The null terminator
C
A newline character
D
An EOF marker
17

The function fgets() reads a string from a file until a newline, EOF, or what other condition is met?

A
A space is encountered
B
num-1 characters have been read
C
A tab character is read
D
The string becomes too long
18

Which of the following modes opens a text file for both reading and writing, assuming the file must already exist?

A
a+
B
w+
C
r
D
r+
19

What is a binary stream?

A
A sequence of characters with translations
B
A sequence of text lines
C
A sequence of bytes with one-to-one correspondence to the external device
D
A stream for images only
20

What is a text stream?

A
A sequence of bytes without translation
B
A sequence of characters where translations like newline to CR/LF can occur
C
A stream that can only contain letters
D
A stream that is always human-readable
21

How do you represent a pointer to an integer?

A
int ptr;
B
int &ptr;
C
int *ptr;
D
ptr int;
22

The 'a' mode for opening a file is used for what purpose?

A
Appending data to the end of a file
B
Reading a file from the beginning
C
Overwriting an existing file
D
Creating a new file only
23

If a file does not exist and is opened in 'a' mode, what happens?

A
An error is returned
B
The file is created
C
The program exits
D
A NULL pointer is returned
24

What is the purpose of the second argument in the fopen() function?

A
To specify the file pointer
B
To specify the file name
C
To specify the file opening mode
D
To specify the buffer size
25

A pointer is a memory cell whose content is the ________ of another memory cell.

A
value
B
data type
C
name
D
address
26

The contents of the memory location pointed to by a pointer 'var' are referred to as:

A
&var
B
*var
C
ptr(var)
D
address(var)
27

What does the function gets() do?

A
Reads a string from a file
B
Reads a character from the keyboard
C
Reads a string from the keyboard
D
Reads an integer from the keyboard
28

What symbol is used as a separator in the contacts.txt example file?

A
:
B
,
C
!
D
#
29

In the gotoxy(col, row) function, what does 'col' represent?

A
The column number
B
The color code
C
The character to print
D
The row number
30

The functions fprintf() and fscanf() are similar to printf() and scanf() but they work with:

A
The console
B
Files
C
Binary data only
D
Strings only
31

If a file is not in the current directory, what must be provided in its name to fopen()?

A
Only the file name
B
A special flag
C
Its absolute path
D
Its size
32

When providing an absolute path in a string in C, what must be done with backslashes?

A
They must be replaced with forward slashes
B
They must be doubled (e.g., \\\\)
C
They must be removed
D
They must be enclosed in quotes
33

What is returned by fgets() if an error occurs?

A
EOF
B
An empty string
C
A null pointer
D
A negative value
34

How can you declare a string variable named 'city' that can hold up to 20 characters?

A
char city[20];
B
string city[20];
C
char city(20);
D
str city[20];
35

The statement `name = "John";` for a string variable 'name' will cause:

A
Successful assignment
B
A warning
C
An error
D
The program to crash
36

What is the subscript of the first element in a C array?

A
1
B
0
C
-1
D
Depends on the declaration
37

The `putc()` function takes a character and what other argument?

A
The file name
B
A buffer pointer
C
The file pointer (FILE *fp)
D
The character's position
38

In a text file, what is placed at the end of each line when the ENTER key is pressed?

A
EOF
B
\\0
C
\\n
D
\\t
39

Which mode opens a text file for both reading and appending?

A
r+
B
w+
C
a+
D
a
40

What does the `strlen()` function (used in the examples) do?

A
Copies a string
B
Compares two strings
C
Concatenates two strings
D
Returns the length of a string
41

A file is defined as a set of related:

A
records
B
streams
C
pointers
D
functions
42

The `fscanf()` function is used for what purpose?

A
Formatted output to a file
B
Formatted input from a file
C
Unformatted input from a file
D
Opening a file in scan mode
43

The `fprintf()` function is used for what purpose?

A
Formatted input from a file
B
Unformatted output to a file
C
Formatted output to a file
D
Printing file properties
44

In C, a file can refer to:

A
A disk file only
B
The screen and keyboard only
C
A disk file, the screen, the keyboard, a port, etc.
D
A variable in memory only
45

Which function is used to move the cursor to a specific location on the screen in the examples?

A
move_cursor()
B
gotoxy()
C
setpos()
D
cursor()
46

What is the main advantage of `fprintf()` and `fscanf()`?

A
They are faster than other functions
B
They work with binary data
C
They make it easy to write a wide variety of data to a file using a text format
D
They automatically close the file