Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Language in C Interview Questions and Answers

Ques 56. How to obtain the current drive through C ?

Ans. 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: %c\n", 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
Ans. 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 ?

Ans. 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 ( "Just\n To\n Test\n Where\n the cursor\n goes" ) ;

printf ( "Current location is X: %d Y: %d\n", wherex( ), wherey( ) ) ;
}
Is it helpful? Add Comment View Comments
Ques 59. How do I programmatically delete lines in the text window?

Ans. 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 %d\r\n", 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 ?

Ans. 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:

©2016 WithoutBook