Question: 50
(Choose 1 answer)
Consider the following code snippet that reads and prints the contents of a text file named "data.txt":
#include <stdio.h>
int main() {
FILE *file_ptr;
char ch;
file_ptr fopen("data.txt", "r");
if (file_ptr == NULL) {
printf("Unable to open the file.\n");
return 1;
while ((ch = fgetc(file_ptr)) != EOF) {
printf("%c", ch);
fclose(file_ptr);
return 0;
What will be the output of this code when executed, assuming "data.txt" contains the following text:
Hello
This is a sample text file.
A. Hello
This is a sample text file.
B. Hello
C. This is a sample text file.
D. This is a sample text file.
Hello