1.
In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?
Correct Answer
C. "I am a boy\n\0"
Explanation
The correct answer is "I am a boy\0". When the line "I am a boy\r" is read into the array using fgets(), it will include the carriage return character '\r' at the end of the string. The '\r' represents a carriage return, which is a control character used to move the cursor to the beginning of the line. The '\0' represents the null character, which is used to terminate the string. Therefore, the resulting string in the array will be "I am a boy\0".
2.
What is the purpose of "rb" in fopen() function used below in the code?
Correct Answer
A. Open "source.txt" in binary mode for reading
Explanation
The purpose of "rb" in the fopen() function is to open the file "source.txt" in binary mode for reading. The "b" in "rb" indicates that the file should be opened in binary mode, which means that the file will be read as a sequence of bytes rather than as text. This is useful when working with files that contain non-textual data, such as images or audio files.
3.
Which of the following operations can be performed on the file "NOTES.TXT" using the below code?
Correct Answer
D. Read and Write
Explanation
The code provided does not explicitly mention any specific operation being performed on the file "NOTES.TXT". However, the code suggests that it is capable of both reading and writing to the file. Therefore, the correct answer is "Read and Write".
4.
What does fp point to in the program ?
Correct Answer
B. A structure which contains a char pointer which points to the first character of a file.
Explanation
The correct answer is a structure which contains a char pointer which points to the first character of a file. This is because in most programming languages, when we open a file, we use a file pointer (fp) to keep track of the file's location. The file pointer is a structure that contains information about the file, including a char pointer that points to the first character in the file. Therefore, fp points to a structure which contains a char pointer pointing to the first character of the file.
5.
To print out a and b given below, which of the following printf() statement will you use?
Correct Answer
A. Printf("%f %lf", a, b);
Explanation
The correct answer is printf("%f %lf", a, b) because it correctly specifies the format specifiers for the variables a and b. The %f specifier is used for float variables, while the %lf specifier is used for double variables. Therefore, this printf statement will correctly print out the values of a and b. The other printf statements either use incorrect format specifiers or mix up the order of the specifiers, which would result in incorrect output.
6.
Which files will get closed through the fclose() in the following program?
Correct Answer
D. Error in fclose()
Explanation
The correct answer is "Error in fclose()". This means that there is an error in the fclose() function in the program, and therefore no files will get closed.
7.
On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?
Correct Answer
B. Trh
Explanation
The contents of the 'target.txt' file will be "Trh". This is because the program reads the source file and only writes the second and third characters of each line to the target file. In the given source line "To err is human", the second character is 'r' and the third character is 'r', so only "Trh" will be written to the target file.
8.
To scan a and b given below, which of the following scanf() statement will you use?
Correct Answer
D. Scanf("%f %lf", &a, &b);
Explanation
The correct answer is scanf("%f %lf", &a, &b); because the format specifier %f is used to scan a float value, and the format specifier %lf is used to scan a double value. Since the variables a and b are of type float and double respectively, this scanf statement is the correct one to use.
9.
Out of fgets() and gets() which function is safe to use?
Correct Answer
B. Fgets()
Explanation
fgets() is the safer function to use out of fgets() and gets(). The gets() function is considered unsafe because it does not perform any bounds checking on the input, which can lead to buffer overflow vulnerabilities. On the other hand, fgets() allows you to specify the maximum number of characters to read, preventing buffer overflow issues.
10.
Consider the following program and what will be content of t?
Correct Answer
B. The handle associated with "DUMMY.C" file
Explanation
The content of "t" will be the handle associated with the "DUMMY.C" file. This means that "t" will contain the identifier or reference to the file "DUMMY.C", allowing the program to perform operations on that file such as reading or writing data.