You are on page 1of 7

Sources / sites

http://www.cquestions.com/2012/02/data-type-questions-in-c.html

http://www.indiabix.com/c-programming/pointers/

Directions

Step 1 : Identify solution without any assistance (compiler, text book, Google, etc).

Step 2 : Research (text book, Google), work (compiler), and implement the solution.

Step 3: Compare your expected result and actual result.

Resolve the difference by collaborating and corroborating with your classmates. If still not resolved, check with me.

Due to compilers using different standards and some not conforming to standards, it is possible for the output to be different or
incorrect. So its important that you identify the correct version and use that as reference for the exam preparation.

If the code generates a compilation error, then identify the reason for the error and fix it.
Questions Lesson(s) Learned
1 What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
A. open "source.txt" in binary mode for reading
B. open "source.txt" in binary mode for reading and writing
C. Create a new file "source.txt" for reading and writing
D. None of above

2 Which of the following operations can be performed on the file "NOTES.TXT" using the
below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");
A. Reading
B. Writing
C. Appending
D. Read and Write
3 Which files will get closed through the fclose() in the following program?
#include<stdio.h>

void main()
{
FILE *fs, *ft, *fp;
fp = fopen("A.C", "r");
fs = fopen("B.C", "r");
ft = fopen("C.C", "r");
fclose(fp, fs, ft);
}

4 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>

void main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c[0] = getc(fs);
fseek(fs, 0, SEEK_END);
fseek(fs, -3L, SEEK_CUR);
fgets(c, 5, fs);
puts(c);
}
5 Point out the error in the program?
#include<stdio.h>

void main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20L", SEEK_SET);
fclose(fp);
}
6 Point out the error in the program?
#include<stdio.h>

/* Assume there is a file called 'file.c' in c:\tc directory. */


void main()
{
FILE *fp;
fp=fopen("c:\\tc\\file.c", "r");
if(!fp)
printf("Unable to open file.");

fclose(fp);
}
A. No error, No output.
B. Program crashes at run time.
C. Output: Unable to open file.
D. None of above

7 Point out the error in the program?


#include<stdio.h>

/* Assume there is a file called 'file.c' in c:\tc directory. */


void main()
{
FILE *fp;
fp=fopen("c:\\tc\\file.c", "r");
if(!fp)
printf("Unable to open file.");
else
fprintf(fp,”Hello World”);
fclose(fp);
}
A. No error, No output.
B. Program crashes at run time.
C. Output: Unable to open file.
D. None of above
8 Offset used in fseek() function call can be a negative number.
A. True
B. False

9 We should not read after a write to a file without an intervening call to fflush(), fseek() or
rewind()
A. True
B. False

10 stderr, stdin, stdout are FILE pointers


A. Yes
B. No

11 Function fseek may seek


a) relative to the beginning of a file.
b) relative to the end of a file
c) relative to the current location of a file
d) all the above
e) none of the above

12 You must explicitly use fopen to open the standard input, standard output and
standard error streams.
13 Function ______________ re positions the file position pointer to a specific location in
the file.
14 Data in sequential-access files is always updated without overwriting other data
15 For proper operations, records in random-access files should be of uniform length
16 The file "tools.dat" should be opened to add data to the file without discarding the current
data.
Which of the following is the correct statement?

a) fPtr = fopen( "tools.dat", "w" )


b) fPtr = fopen( "tools.dat", "a" )
c) fPtr = fopen( "tools.dat", "r" )
d) fPtr = fopen( "tools.dat", "w+" )
e)
17 A program can skip the function fclose that is used to close a file?
18 Intentionally left blank

You might also like