Question on console input output

Last Updated: Jan 19, 2013

Jan 19 • General, Notes, Opinion • 1853 Views • 1 Comment on Question on console input output

Q1: what is console input output?
ans:The I/O functions provide a simple way to read a stream of characters from console input or to write a stream of characters to console output. A read operation gets input characters from a console’s input buffer and stores them in a specified buffer. A high-level write operation takes characters from a specified buffer and writes them to a screen buffer at the current cursor location, advancing the cursor as each character is written.

Q2:explain briefly the concept of console input output?
ans:Input/Output is the interface between the computer and the outside world. Simple input/output consists of switches, relay contacts, indicators, etc. Two other classes of I/O are console I/O and mass storage I/O. The latter would include tape or disk or any other method (usually using magnetic medium) of storing and retrieving large records or files. I’m limiting my discussion here to console I/O.

Q3:What is the purpose of “rb” in fopen() function used below in the code?
FILE *fp;
fp = fopen(‘source.txt”,”rb”);
ans:The file source.txt will be opened in the binary mode.

Q4:What does fp point to in the program ?

#include

int main()
{
FILE *fp;
fp=fopen(“trial”, “r”);
return 0;
}

ans:A structure which contains a char pointer which points to the first character of a file.

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

#include

float a=3.14;
double b=3.14;
ans:To print a float value, %f is used as format specifier.

To print a double value, %lf is used as format specifier.

Therefore, the answer is printf(“%f %lf”, a, b);

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

#include

float a;
double b;

ans:To scan a float value, %f is used as format specifier.

To scan a double value, %lf is used as format specifier.

Therefore, the answer is scanf(“%f %lf”, &a, &b);

Q7:Out of fgets() and gets() which function is safe to use?
ans:because, In fgets() we can specify the size of the buffer into which the string supplied will be stored.

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

#include

int main()
{
FILE *fp;
int t;
fp = fopen(“DUMMY.C”, “w”);
t = fileno(fp);
printf(“%d\n”, t);
return 0;

ans:fp=fopen(“DUMMY.C”, “w”); A file DUMMY.C is opened in write mode and returns the file pointer to fp

t = fileno(fp); returns the handle for the fp stream and it stored in the variable t

printf(“%d\n”, t); It prints the handle number

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

#include

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 0;
}

ans: Error in fclose() due to Extra parameter in call to fclose().

Q10:what is the error in the program?

#include

int main()
{
FILE *fp;
fp=fopen(“trial”, “r”);
fseek(fp, “20”, SEEK_SET);
fclose(fp);
return 0;
}

ans:Error: fseek() long offset value because Instead of “20” use 20L since fseek() need a long offset value.


Discover more from Our Education | Best Coaching Institutes Colleges Rank

Subscribe to get the latest posts sent to your email.

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published. Required fields are marked *

One Response to Question on console input output

  1. Saheli Dasgupta says:

    This article gives us a detailed information about what console input output is. Should go through this. A very good effort by the author to give the readers quality information about console input output in a nutshell.

« »