Language in C اسئلة واجوبة المقابلات
Question: How do I write code to find an amount of free disk space available on current drive?
Answer: Use getdfree( ) function as shown in follow code.#include <stdio.h> #include <stdlib.h> #include <dir.h> #include <dos.h> main( ) { int dr ; struct dfree disk ; long freesp ; dr = getdisk( ) ; getdfree ( dr + 1 , &disk ) ; if ( disk.df_sclus == 0xFFFF ) { printf ( "ngetdfree( ) function failedn"); exit ( 1 ) ; } freesp = ( long ) disk.df_avail * ( long ) disk.df_bsec * ( long ) disk.df_sclus ; printf ( "nThe current drive %c: has %ld bytes available as free spacen", 'A' + dr, freesp ) ; } 17. Use of array indices... If we wish to store a character in a char variable ch and the character to be stored depends on the value of another variable say color (of type int), then the code would be as shown below: switch ( color ) { case 0 : ch = 'R' ; break ; case 1 : ch = 'G' ; break ; case 2 : ch = 'B' ; break ; } In place of switch-case we can make use of the value in color as an index for a character array. How to do this is shown in following code snippet. char *str = "RGB' ; char ch ; int color ; // code ch = str[ color ] ; |
احفظ للمراجعة
احفظ هذا العنصر في الإشارات المرجعية، او حدده كصعب، او ضعه في مجموعة مراجعة.
سجل الدخول لحفظ الإشارات المرجعية والاسئلة الصعبة ومجموعات المراجعة.
هل هذا مفيد؟ نعم لا
الاكثر فائدة حسب تقييم المستخدمين:
- What will be the output of the following code?
void main ()
{ int i = 0 , a[3] ;
a[i] = i++;
printf ("%d",a[i]) ;
} - Why doesn't the following code give the desired result?
int x = 3000, y = 2000 ;
long int z = x * y ; - Why doesn't the following statement work?
char str[ ] = "Hello" ;
strcat ( str, '!' ) ; - How do I know how many elements an array can hold?
- How do I compare character data stored at two different memory locations?