Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language in C Interview Questions and Answers

Test your skills through the online practice test: Language in C Quiz Online Practice Test

Ques 21. When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?

When we open a file for read/write operation using function like fopen( ), it returns a pointer to the structure of type FILE. This structure stores the file pointer called position pointer, which keeps track of current location within the file. On opening file for read/write operation, the file pointer is set to the start of the file. Each time we read/write a character, the position pointer advances one character. If we read one line of text at a step from the file, then file pointer advances to the start of the next line. If the file is opened in append mode, the file pointer is placed at the very end of the file. Using fseek( ) function we can set the file pointer to some other place within the file.

Is it helpful? Add Comment View Comments
 

Ques 22. The sizeof( ) function doesnâ??t return the size of the block of memory pointed to by a pointer. Why?

The sizeof( ) operator does not know that malloc( ) has been used to allocate a pointer. sizeof( ) gives us the size of pointer itself. There is no handy way to find out the size of a block allocated by malloc( ).

Is it helpful? Add Comment View Comments
 

Ques 23. Compare FP_SEG And FP_OFF.

Sometimes while working with far pointers we need to break a far address into its segment and offset. In such situations we can use FP_SEG and FP_OFF macros. Following program illustrates the use of these two macros.
#include

main( )
{
unsigned s, o ;
char far *ptr = "Hello!" ;

s = FP_SEG ( ptr ) ;
o = FP_OFF ( ptr ) ;
printf ( "n%u %u", s, o ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 24. How do I write a program to convert a string containing number in a hexadecimal form to its equivalent decimal?

The following program demonstrates this:
main( )
{
char str[] = "0AB" ;
int h, hex, i, n ;
n = 0 ; h = 1 ;
for ( i = 0 ; h == 1 ; i++ )
{
if ( str[i] >= '0' && str[i] <= '9' )
hex = str[i] - '0' ;
else
{
if ( str[i] >= 'a' && str[i] <= 'f' )
hex = str[i] - 'a' + 10 ;
else
if ( str[i] >= 'A' && str[i] <= 'F' )
hex = str[i] - 'A' + 10 ;
else
h = 0 ;
}
if ( h == 1 )
n = 16 * n + hex ;
}
printf ( "nThe decimal equivalent of %s is %d",
str, n ) ;
}
The output of this program would be the decimal equivalent of 0AB is 171.

Is it helpful? Add Comment View Comments
 

Ques 25. How do I write code that reads the segment register settings?

We can use segread( ) function to read segment register settings. There are four segment registersâ??code segment, data segment, stack segment and extra segment. Sometimes when we use DOS and BIOS services in a program we need to know the segment register's value. In such a situation we can use segread( ) function. The following program illustrates the use of this function.
#include <dos.h>
main( )
{
struct SREGS s ;
segread ( &s ) ;
printf ( "nCS: %X DS: %X SS: %X ES: %X",s.cs,
s.ds, s.ss, s.es ) ;
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook