Social Icons

Monday, December 10, 2012

C LANGUAGE INTERVIEW PAPERS ANSWERS & QUESTIONS


78.What is a stream ?
Ans:
A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream receives the output from the program and is known as output stream
.

79.What is meant by file opening ?
Ans:
The action of connecting a program to a file is called opening of a file. This requires creating
an I/O stream before reading or writing the data.


80.What is FILE ?
Ans:
FILE is a predefined data type. It is defined in stdio.h file.


81.What is a file pointer ?
Ans:
The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer
points to the block of information of the stream that had just been opened.


82.How is fopen() used ?
Ans:
The function fopen() returns a file pointer. Hence a file pointer is declared and it is assigned
as  FILE *fp;
fp= fopen(filename,mode);
filename is a string representing the name of the file and the mode represents:
“r” for read operation
“w” for write operation
“a” for append operation
“r+”,”w+”,”a+” for update operation


83How is a file closed ?
Ans:
A file is closed using fclose() function
Eg. fclose(fp);
Where fp is a file pointer.


84.What is a random access file ?
Ans:
A file can be accessed at random using fseek() function
fseek(fp,position,origin);
fp -- file pointer
position  -- number of bytes offset from origin
origin -- 0,1 or 2 denote the beginning ,current position or end of file respectively.


85.What is the purpose of ftell ?
Ans:
The function ftell() is used to get the current file represented by the file pointer.
ftell(fp);
returns a long integer value representing the current file position of the file pointed by the
file pointer fp. If an error occurs ,-1 is returned.


86.What is the purpose of rewind() ?
Ans:
The function rewind is used to bring the file pointer to the beginning of the file.
Rewind(fp);
Where fp is a file pointer. Also we can get the same effect by fseek(fp,0,0);


87.Difference between a array name and a pointer variable ?
Ans:
A pointer variable is a variable where as an array name is a fixed address and is not a
variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value ,++ and -- operators cannot be applied to it.


88.Represent a two-dimensional array using pointer ?
Ans:

Address of a[I][j] Value of a[I][j]
&a[I][j]
or
a[I] + j
or
*(a+I) + j
*&a[I][j] or a[I][j]
or
*(a[I] + j )
or
*( * ( a+I) +j )


89.Difference between an array of pointers and a pointer to an array ?
Ans:

Array of pointers & Pointers to an array
1- Declaration is: data_type *array_name[size];
2-Size represents the row size.
2- The space for columns may be dynamically
1-Declaration is
data_type ( *array_name)[size];
2-Size represents the column size.

No comments:

Post a Comment