Ex 1: What is the output?
#include "stdio.h"
{
unsigned char ch;
FILE *fp ;
fp = fopen ( "trial", "r" ) ;
while ( ( ch = getc ( fp ) ) != EOF )
printf ( "%c", ch ) ;
fclose ( fp ) ;
}
Ans:
Compile time error.
Explanation:
There is no main function. |
Ex 2: What is the output?
#include<stdio.h>
main( )
{
FILE *fp ;
char name[25] ;
int age ;
fp = fopen ( "YOURS", "r" ) ;
while ( fscanf ( fp, "%s %d", name, &age ) != NULL )
fclose ( fp ) ;
}
Ans::
Infinite loop formed.
Explanation:
fscanf returns the number of input fields successfully scanned, converted,
and stored. Here fscanf scanned two fields, so it return 1. |