Input & Output
- What will be the output of the following C code if 2 character is typed by the user?
#include <stdio.h>
#include <string.h>
int main()
{
char line[25];
fgets(line, 25, stdin);
printf("%d\n", line[2]);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
64
- What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char line[25];
FILE *fp;
fp = fopen("file.txt", "r");
while (fgets(line, 25, fp))
fputs(line, stdout);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Segmentation fault
- gets() does the following when it reads from stdin.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Deletes the terminating ‘n’
- fputs() function writes a string to a file that only ends with a newline.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
False
- The syntax of fgets is char *fgets(char *line, int maxline, FILE *fp). Which is true for fgets?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Both On end of file or error it returns NULL & returns line on success