C Interview Questions Part 18

Q:What is the difference between ordinary variable and pointer in C?
A: An ordinary variable is like a container it can hold any value and we can change the value of ordinary variable at a time throughout the program .A pointer is a variable that stores the address of another Variable.

Q:What are segment and offset addresses?
A: When paging technique is performed, the page will breaks into segments and its sequence is said to be segments and its width can be said as offset. In short,segment is a physical address and offset is logical address.

Q:What is "far" and "near" pointers in "c" ?
A:“Near" and "far" pointers are actually non-standard qualifiers that you'll find only on x86 systems. They reflect the odd segmentation architecture of Intel processors. In short, a near pointer is an offset only,which refers to an address in a known segment. A far pointer is a compound value, containing both a segment number and an offset into that segment. Segmentation still exists on Intel processors, but it is not used in any of the mainstream 32-bit operating systems developed for them, so you'll generally only find the "near" and "far" keywords in source code developed for Windows 3.x,MS-DOS, Xenix/80286, etc.

Q:When should a type cast be used?
A:There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.
The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure.
struct foo *p = (struct foo *) malloc(sizeof(struct foo));

Q:What is the difference between %d and %*d in c language?
A: %d give the original value of the variable and %*d give the address of the variable.
eg:-int a=10,b=20;
printf("%d%d",a,b);
printf("%*d%*d",a,b);
Result is 10 20 1775 1775 .Here 1775 is the starting address of the memory allocation for the integer.a and b having same address because of contagious memory allocation.