Correct Answer: #include "dosh" main() { Char far *scr = ( char far *) 0xB8000000; Char *seg, *off; Seg = (char *) FP_SEG ( scr ); Off = ( char *) FP_OFF ( scr ); }
2. What would be the output of the following program, if the array beigns at address 65486? main() { int arr[] = {12,14,15,23,45}; printf ("%u %u", arr, &arr); }
Correct Answer: An error would be reported in the statement k++ since arithmetic on void pointers is not permitted unless the void pointer is appropriately typecasted
4. How would you eliminate the warning generated on complaining the following program? main() { char far *scr; scr = 0xB8000000; *scr = 'A'; }
Correct Answer: A typedef defines a new name for a type, and in simpler cases like the one shown below you can define a new structure type and a typedef for it at the same time typedef struct { char name[20]; int age; } emp; However, in the structure defined in this question, there is an error because a typedef declaration cannot be used until it is defined In the given code fragment the typedef declaration is not yet defined at he point where the link field is declared
7. If the following structure is written to a file using fwrite(), can fread() read it back successfully? struct emp { char *n; int age; }; struct emp e = { "Sujay",15}; FILE *fp; fwrite (&e, sizeof (e), 1, fp);
Correct Answer: No, since the structure contains a char pointer while writing the structure to the disk using fwrite() only the value stored in the pointer n would get written When this structure is read back the address would be read back but it is quite unlikely that the desired string would be present at this address in memory
8. What would be the output of the following program? main() { struct emp { char *n; int age; }; struct emp e1 = { "Dravid", 23}; struct emp e2 = e1; strupr (e2.n); printf ("\n%s",e1.n); }
Correct Answer: DRAVID When a structure is assigned, passed, or returned, the copying is done monolithically This means that the copies of any pointer fields will point to the same place as the original In other words, anything pointed to is not copied Hence, on changing the name through e2n it automatically changed e1n
9. How would you check whether the contents of two structure variables are same or not?
Correct Answer: struct emp { char n[20]; int age; }; main() { struct emp e1 = {"Dravid", 23}; struct emp e2; scanf ("%s %d",e2n, & e2age); if( structcmp (e1,e2) ==0) printf ("The structures are equal"); else printf ("The structures are unequal"); } structcmp ( struct emp x, struct emp y) { if (strcmp (xn,yn) ==0) if (xage == yage) return (0); return (1); } In short, if you nee to compare two structures, you'll have to write your own function to do so which carries out the comparison field by field
10. Point out the error, if any, in the following program. # include "stdio.h" main() { FILE *fp; char str[80]; fp = fopen ("trail", "r"); while (!feof (fp)) { fgets (str, 80, fp); puts (str); } fclose (fp); }