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?
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 ?
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?
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?
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?
fp = fopen(“DUMMY.C”, “w”);
t = fileno(fp);
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?
FILE *fs, *ft, *fp;
fp = fopen(“A.C”, “r”);
fs = fopen(“B.C”, “r”);
ft = fopen(“C.C”, “r”);
fclose(fp, fs, ft);
ans: Error in fclose() due to Extra parameter in call to fclose().
Q10:what is the error in the program?
fseek(fp, “20”, SEEK_SET);
ans:Error: fseek() long offset value because Instead of “20” use 20L since fseek() need a long offset value.