1.
Compare arrays and structures.
2. Compare structures and unions.
3.
Define Structure in C.
A structure contains one or more data
items of different data type in which the individual elements can differ in
type.
A simple structure may contain the
integer elements, float elements and character elements etc. and the individual
elements are called members.
Example: struct result
{
int
marks;
float
avg;
char
grade;
}std;
4. Rules for declaring a structure?
A structure must end with a semicolon.
Usually a structure appears at the top of the source
program.
Each structure element must be terminated.
The structure must be accessed with structure
variable with dot (.) operator.
5.
Define structure pointers
Pointer is a variable, it contain address of another
variable and the structure pointers are declared by placing * in front of a
structure variable‟s name.
Example: struct result
{
int
marks;
float
avg;
char
grade;
};
struct
result *sam;
6.
Define union?
A union, is a collection of variables of
different types, just like structure. Union is a derived data type and the
difference between union and structure is in terms of storage.
In structure each member has its own
storage location, whereas all the members of union use the same memory
location.
Example: union result
{
int
marks;
float
avg;
char
grade;
}std;
7.
Define file?
A file is a collection of bytes stored
on a secondary storage device, which is generally a disk of some kind. The
collection of bytes may be interrupted, for example, as characters, words,
lines, paragraph and pages from a textual document.
Example: FILE *infile;
FILE
*outfile;
8.
Define binary files?
Binary files can be processed sequentially or,
depending on the needs of the application, they can process using random access
techniques.
In C, processing a file
using random access techniques involves moving the current file position to an
appropriate place in the file before reading or writing data.
9. Define opening a file?
A file requires to be
opened first with the file pointer positioned on the first character. No
input-output functions on a stream can be performed unless it is opened.
When a stream is
opened, it is connected to named DOS device or file .C provides a various
functions to open a file as a stream.
Syntax: FILE
*fopen(char * filename, char *mode);
10. Define fseek()?
fseek() will position
the file pointer to a particular byte within the file. The file pointer is a
pointer is a parameter maintained by the operating system and determines where
the next read will comes from , or to where the next write will go.
11.
Functions of bit fileds?
Bit fields do not have address.
It is not an
array.
It cannot be
accessed using pointer.
It cannot be
store values beyond their limlits. If larger values are assigned, the output is
undefined.
12.
What are the ways to detecting End
of File?
In Text file:
Special character EOF denotes the end of file.
As soon as character is read, end of the file can be
detected
EOF is defined in stdio.h
Equivalent value of EOF is -1
In
binary file:
feof function is used to detect the end of file
it can be used in text file.
feof returns TRUE if end of the file is reached
Syntax: int feof(FILE *fp);
13.
What are key functions required to
process a file?
fopen
fclose
fseek
fread
fwrite
13.
List out the file handling
functions
fopen()-create a new file or open a existing file
fclose-close a file
getc()-reads a character from a file putc()-writes a
character to file fscanf()-reads a set of data from a file
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.