Q.1

If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?

#include<stdio.h>

int main()
{
    FILE *fs, *ft;
    char c[10];
    fs = fopen("source.txt", "r");
    c[= getc(fs);
    fseek(fs,SEEK_END);
    fseek(fs, -3L, SEEK_CUR);
    fgets(c,fs);
    puts(c);
    return}
  • friend
  • frien
  • end
  • Error in fseek();
Q.2

What will be the output of the program ?

#include<stdio.h>

int main()
{
    FILE *fp;
    char ch, str[7];
    fp=fopen("try.c", "r"); /* file 'try.c' contains "This is Nagpur" */
    fseek(fp, 9L, SEEK_CUR);
    fgets(str,fp);
    puts(str);
    return}
  • agpur
  • gpur
  • Nagp
  • agpu
Q.3

Point out the error in the program?

#include<stdio.h>

/* Assume there is a file called 'file.c' in c:\tc directory. */
int main()
{
    FILE *fp;
    fp=fopen("c:\tc\file.c", "r");    
    if(!fp) 
      printf("Unable to open file.");        

    fclose(fp);
    return}
  • No error, No output.
  • Program crashes at run time.
  • Output: Unable to open file.
  • None of above
Q.4

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()

  • True
  • False
Q.5

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char *p;
    p="%d\n";
    p++;
    p++;
    printf(p-23);
    return}
  • 21
  • 23
  • Error
  • No output
Q.6

What will be the output of the program ?

#include<stdio.h>

int main()
{
    float a=3.
    printf("%2.1f\n", a);
    return
}
  • 3.00
  • 3.15
  • 3.2
  • 3
Q.7

What will be the output of the program if value 25 given to scanf()?

#include<stdio.h>

int main()
{
    int i;
    printf("%d\n", scanf("%d", &i));
    return}
  • 25
  • 2
  • 1
  • 5
Q.8

Point out the error/warning in the program?

#include<stdio.h>

int main()
{
    unsigned char ch;
    FILE *fp;
    fp=fopen("trial", "r");
    while((ch = getc(fp))!=EOF)
        printf("%c", ch);
    fclose(fp);
    return}
  • Error: in unsigned char declaration
  • Error: while statement
  • No error
  • It prints all characters in file "trial"
Q.9

In a call to printf() function the format specifier %b can be used to print binary equivalent of an integer.

  • True
  • False
Q.10

What will be the output of the program ?

#include<stdio.h>

int main()
{
    FILE *ptr;
    char i;
    ptr = fopen("myfile.c", "r");
    while((i=fgetc(ptr))!=NULL)
        printf("%c", i);
    return}
  • Print the contents of file "myfile.c"
  • Print the contents of file "myfile.c" upto NULL character
  • Infinite loop
  • Error in program
Q.11

What will be the output of the program ?

#include<stdio.h>

int main()
{
    printf("%%%%\n");
    return}
  • %%%%%
  • %%
  • No output
  • Error
Q.12

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?

  • "I am a boy\r\n\0"
  • "I am a boy\r\0"
  • "I am a boy\n\0"
  • "I am a boy"
Q.13

What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;
fp = fopen("source.txt", "rb");
  • open "source.txt" in binary mode for reading
  • open "source.txt" in binary mode for reading and writing
  • Create a new file "source.txt" for reading and writing
  • None of above
Q.14

Which files will get closed through the fclose() in the following program?

#include<stdio.h>

int main()
{
    FILE *fs, *ft, *fp;
    fp = fopen("A.C", "r");
    fs = fopen("B.C", "r");
    ft = fopen("C.C", "r");
    fclose(fp, fs, ft);
    return}
  • "A.C" "B.C" "C.C"
  • "B.C" "C.C"
  • "A.C"
  • Error in fclose()
Q.15

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"?

#include<stdio.h>

int main()
{
    int i, fss;
    char ch, source[= "source.txt", target[20]="target.txt", t;
    FILE *fs, *ft;
    fs = fopen(source, "r");
    ft = fopen(target, "w");
    while(    {
        ch=getc(fs);
        if(ch==EOF)
            break;
        else
        {
            fseek(fs, 4L, SEEK_CUR);
            fputc(ch, ft);
        }
    }
    return}
  • r n
  • Trh
  • err
  • None of above
Q.16

Which of the following operations can be performed on the file "NOTES.TXT" using the below code?

FILE *fp;
fp = fopen("NOTES.TXT", "r+");
  • Reading
  • Writing
  • Appending
  • Read and Write
Q.17

To scan a and b given below, which of the following scanf() statement will you use?

#include<stdio.h>

float a;
double b;
  • scanf("%f %f", &a, &b);
  • scanf("%Lf %Lf", &a, &b);
  • scanf("%f %Lf", &a, &b);
  • scanf("%f %lf", &a, &b);
Q.18

To print out a and b given below, which of the following printf() statement will you use?

#include<stdio.h>

float a=3.double b=3.
  • printf("%f %lf", a, b);
  • printf("%Lf %f", a, b);
  • printf("%Lf %Lf", a, b);
  • printf("%f %Lf", a, b);
Q.19

Out of fgets() and gets() which function is safe to use?

  • gets()
  • fgets()
Q.20

Consider the following program and what will be content of t?

#include<stdio.h>

int main()
{
    FILE *fp;
    int t;
    fp = fopen("DUMMY.C", "w");
    t = fileno(fp);
    printf("%d\n", t);
    return}
  • size of "DUMMY.C" file
  • The handle associated with "DUMMY.C" file
  • Garbage value
  • Error in fileno()
0 h : 0 m : 1 s