Prepare for your Next Interview
This is a discussion on pointers and union? within the C and C++ forums, part of the Software Development category; 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...
|
|||
|
pointers and union?
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 |
| Sponsored Links |
|
|||
|
Quote:
union hold save [10];// arry type union hold *p;// pointer pointer to structure ordinary pointer double pointer |
|
|||
|
Re: pointers and union?
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. |
|
|||
|
Re: pointers and union?
Quote:
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| difference between Union All and full outer join | bvani | MY SQL | 5 | 4 Weeks Ago 05:29 PM |
| Union and Union All in Informatica | ravinuthala | Data Warehousing | 2 | 06-05-2007 03:52 AM |
| UNION does not work in case of CLOB data type | Geek_Guest | SQL | 0 | 05-13-2007 03:15 AM |
| C Programming - Pointers | Lokesh M | C and C++ | 0 | 05-26-2006 02:05 AM |