Pretaining to C language: 1. True or False. A FILE pointer is required to read a
ID: 3838625 • Letter: P
Question
Pretaining to C language:
1. True or False. A FILE pointer is required to read a file
2. True or False. Checking a file is less important when reading rather than Writing
3. True or False. fscanf is space delimited where fgets in newline delimited
4. True or False. To close a file you must include the pointer and the name of the file as arguments
5.True or False.
double chrissy[120] = {0};
creates an array of 120 elements where all elements have the value 0
6. True or False. float brutus [ ] = {5,18,37.59}; results in a syntax error
7. True or False. All values in the array int hawkeye [12] ; must be type integer
8.True or False. It is common to use for loops to fill an array with valuesw
9. True or False. Searching an array for a value is easier if the array has been sorted first
Explanation / Answer
1. True
A file pointer is required for reading a file. Initially file is opened using statement FILE *FP = fopen(filename, mode). Once the file pointer is created, it is used for reading file.
2. True
Checking a file is important while reading rather than writing. While writing if the file doesn't exist, it creates a new one. If already exist, gives a option for overwriting or creating new one based on mode of opening. While reading a file, if file doesn't exist raises an error.
3. True
fscanf reads data and stops reading once it finds whitespace.
fgets reads data until a new line is encountered.
4. False
In order to close a file, just a pointer is required. No need of any file name. File is closed using statement:
fclose(file_pointer)
5. True
Statement double chrissy[120] = {0}; creates an array of 120 elements of indices 0 to 119 and assigns value 0 to all elements.
6. False
Statement float brutus [ ] = {5,18,37.59}; creates a 3 element float array. First two elements are converted implicitly from int to float.
7. True
An array is a collection of homogeneous elements. Therefore as per statement, int hawkeye [12] ; contains all elements of type integer.
8. True
In order to fill an array that contains more than one element. Constructs like loops are used to iterate over each index and assigns values to array elements
9. True
Searching for a value in an array is easier if it is sorted well before searching.
(a) First compare the middle element with key element. If value is found, searching stops.
(b) If key element is less than middle element then search in the left sub array (excluding entire right sub array)
(c) If key element is greater than middle element then search in the right sub array (excluding entire left sub array)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.