hello friends,
here are two ques
1. how union datatype is used in c.?
2. What are different types of pointers?
pls in some detail
have a nice day
hello friends,
here are two ques
1. how union datatype is used in c.?
2. What are different types of pointers?
pls in some detail
have a nice day
union:
- it is hetrogenious collection.
- it reduces memory size compared to structure.
- the union holds any data type even pointers also.
- it takes only highest datatype memory size.
types of pointers:
array of pointers
pointer to pointer
pointer & uion are secondary data types
pointer is used to store the address of variable/value
there are two type of pointer
near pointer
far pointer
union are used to store same memory location is used to store different type of data.
W.r.t your first question, let me list an example.
Each page in memory is represented by a Page Frame Descriptor (pfd). The pfd contains all the information about the physical page like page size, page frame number, etc. A page (or pfd) can be either on the free list OR on the allocated list. It cannot be on both the lists at the same time for obvious reasons. So, if the allocated and free pages are different lists (single or double linked lists), then we need a pointer field in the pfd for each list. This would mean that we need 4 bytes per pointer (32 bit machine) i.e. a total of 8 bytes. But, we just noted that the page cannot be on two lists at the same time. So, we can use a union of the two fields i.e.
union list_struct {
allocated_list_ptr *ap;
free_list_ptr *fp;
}
The advantage is that only 4 bytes of storage are allocated for both the pointers, assuming that only one pointer is in use at any time. Hope this example helps.
2.
The second question needs some clarification. Are you on a DOS/Windows platform OR on a UNIX platform?? On DOS/Windows operating platform, there are different pointer types based on the memory model being used. For example, far pointer, etc. On UNIX, the different types of pointers correspond to the different data types that the pointers can point to. For example, we have int pointers i.e. pointers that point to an int, char pointers, long pointers, etc.
What is the difference between const voletile and voletile ?
Const volatile : your object cannot modify it but any external process could