C Interview Questions and Answers: Why Doesn't The Following Code Give The Desired Result?
C Interview Questions and Answers: Why Doesn't The Following Code Give The Desired Result?
C Interview Questions and Answers: Why Doesn't The Following Code Give The Desired Result?
[C Frequently
int i[32767] ;
float f[16383] ;
char s[65535] ;
}
How do I write code that reads data at memory location specified by segment
and offset?
Use peekb( ) function. This function returns byte(s) read from specific segment and
offset locations in memory. The following program illustrates use of this function. In
this program from VDU memory we have read characters and its attributes of the
first row. The information stored in file is then further read and displayed using
peek( ) function.
#include <stdio.h>
#include <dos.h>
main( )
{
char far *scr = 0xB8000000 ;
FILE *fp ;
int offset ;
char ch ;
if ( ( fp = fopen ( "scr.dat", "wb" ) ) == NULL )
{
printf ( "\nUnable to open file" ) ;
exit( ) ;
}
// reads and writes to file
for ( offset = 0 ; offset < 160 ; offset++ )
fprintf ( fp, "%c", peekb ( scr, offset ) ) ;
fclose ( fp ) ;
if ( ( fp = fopen ( "scr.dat", "rb" ) ) == NULL )
{
printf ( "\nUnable to open file" ) ;
exit( ) ;
}
// reads and writes to file
for ( offset = 0 ; offset < 160 ; offset++ )
{
fscanf ( fp, "%c", &ch ) ;
printf ( "%c", ch ) ;
}
fclose ( fp ) ;
}
What is conversion operator?
class can have a public method for specific data type conversions.
for example:
class Boo
double value;
public:
Boo(int i )
operator double()
{
return value;
};
Boo BooObject;
for example:
Macro:
#define min(i, j) (i < j ? i : j)
template:
template<class T>
T min (T i, T j)
{
return i < j ? i : j;