Unit 6
Unit 6
N
Questions
o.
storage class defines the lifetime, scope, and visibility of a variable or function. It determines how
and where the variable is stored, and how long it exists in memory. Storage classes are crucial for
understanding the behavior of variables, especially in terms of their lifetime (i.e., when they are
created and destroyed), visibility (i.e., where they can be accessed), and scope (i.e., the part of the
program in which they are valid).
1. auto
2. register
3. static
4. extern
Command Line Arguments are inputs given to a C program at the time of execution through the
terminal or command prompt. These arguments are passed to the main() function when the program
starts
Attributes Operations
File Name fopen()
File Descriptor / Pointer fclose()
File Mode fgetc(), fgets(), fread()
File Size fputc()
int main() {
struct stat fileStat;
char filename[100];
10. Find the average in a sequence of numbers in c while ignoring the negative numbers in sequence.
11.
What is a random access file?
Random Access, also known as Direct Access, allows data to be read from or written to any
position in the file without reading through the file sequentially. This type of file processing is
useful for scenarios where quick access to specific parts of the file is needed.
12.
What is the main advantage of using random access files?
Non-Sequential Reading/Writing
13.
In which programming language is a common example of a random access file implemented?
14.
What method is typically used to seek a specific position in a random access file?
fseek(FILE *fp, long offset, int origin): Moves the file pointer to a specified position.
Example:
fseek(fp, 10, SEEK_SET); // Move to the 10th byte from the beginning
15.
How can you write data to a specific record in a random access file?
Open the File in a mode that allows reading and writing (e.g., r+b in C).
Calculate the Byte Offset: Determine the position of the record in the file. For fixed-length records,
you can calculate the offset as record_number * record_size.
Use fseek() (in C) or an equivalent to move the file pointer to the correct position.