Input / Output

Q1:
What will be the output of the program ?
#include<stdio.h>

int main()
{
    FILE *fp;
    unsigned char ch;
     /* file 'abc.c' contains 'This is AptitudeCrack ' */
    fp=fopen('abc.c', 'r');
    if(fp == NULL)
    {
        printf('Unable to open file');
        exit(1);
    }
    while((ch=getc(fp)) != EOF)
        printf('%c', ch);

    fclose(fp);
    printf('\n', ch);
    return 0;
}

A This is AptitudeCrack

B This is

C Infinite loop

D Error

ANS:A - This is AptitudeCrack

The macro EOF means -1. while((ch=getc(fp)) != EOF) Here getc function read the character and convert it to an integer value and store it in the variable ch, but it is declared as an unsigned char. So the while loop runs infinitely.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.