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 56. How to obtain the current drive through C ?

We can use the function _getdrive( ) to obtain the current drive. The _getdrive( ) function uses DOS function 0X19 to get the current drive number

#include <direct.h>
main( )
{
int disk ;
disk = _getdrive( ) + 'A' - 1 ;
printf ( "The current drive is: %cn", disk ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 57. How come the output for both the programs is different when the logic is same?

main( )
{
int i, j ;

for ( i = 1, j = 1 ; i <= 5, j <= 100 ; i++, j++ )
{
gotoxy ( 1, 1, ) ;
printf ( "%d %d", i, j ) ;
}
}

main( )
{
int i, j ;

for ( i =1, j = 1; j <= 100, i <= 5; i++, j++ )
{
gotoxy ( 1, 1 ) ;
printf ( "%d %d", i, j ) ;
}
}

Output -> 5 5

Even if logic of both the programs is same the output of the first program comes out to be 100, 100, but of the second program it is 5, 5. The comma operator plays a vital role inside the for loop. It always considers the value of the latest variable. So, at the time of testing the condition in for loop, the value of j will be considered in the first program and value of i in the second.

Is it helpful? Add Comment View Comments
 

Ques 58. Can we get the x and y coordinate of the current cursor position ?

The function wherex( ) and wherey( ) returns the x-coordinate and y-coordinate of the current cursor position respectively. Both the functions return an integer value. The value returned by wherex( ) is the horizontal position of cursor and the value returned by wherey( ) is the vertical position of the cursor. Following program shows how to use the wherex( ) and wherey( ) functions.

#include <conio.h>
main( )
{
printf ( "Justn Ton Testn Wheren the cursorn goes" ) ;

printf ( "Current location is X: %d Y: %dn", wherex( ), wherey( ) ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 59. How do I programmatically delete lines in the text window?

While writing programs that perform screen-based I/O, you may want to-delete the current line's contents, moving one line up, all of the output that follows. In such cases a function called delline( ) can be used. Following code snippet illustrates the use of function delline( ).

#include <conio.h>
main( )
{
int i ;
clrscr( ) ;

for ( i = 0; i <= 23; i++ )
printf ( "Line %drn", i ) ;

printf ( "Press a key to continue : " ) ;
getch( ) ;

gotoxy ( 2, 6 ) ;

for ( i = 6; i <= 12; i++ )
delline( ) ;

getch( ) ;
}

Is it helpful? Add Comment View Comments
 

Ques 60. How do I get the time elapsed between two function calls ?

The function difftime( ) finds the difference between two times. It calculates the elapsed time in seconds and returns the difference between two times as a double value.

#include <time.h>
#include <stdio.h>
#include <dos.h>

main( )
{
int a[] = { 2, -34, 56, 78, 112, 33, -7, 11, 45, 29, 6 } ;
int s ;
time_t t1, t2 ; // time_t defines the value used for time function

s = sizeof ( a ) / 2 ;
t1 = time ( NULL ) ;
sel_sort ( a, s ) ; // sort array by selection sort
bub_sort ( a, s ) ; // sort array by bubble sort method
t2 = time ( NULL ) ;
printf ( "nThe difference between two function calls is %f", difftime (
t2, t1 ) ) ;
}

In the above program we have called difftime( ) function that returns the time elapsed from t1 to t2.

Is it helpful? Add Comment View Comments
 
}
}

main( )
{
int i, j ;

for ( i =1, j = 1; j <= 100, i <= 5; i++, j++ )
{
gotoxy ( 1, 1 ) ;
printf ( "%d %d", i, j ) ;
}
}

Output -> 5 5
3) Can we get the x and y coordinate of the current cursor position ?

4) How do I programmatically delete lines in the text window?

5) How do I get the time elapsed between two function calls ?

" />

Most helpful rated by users:

©2024 WithoutBook