Results 1 to 7 of 7

Thread: pointers and union?

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Answers
    28

    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


  2. #2
    Contributing Member
    Join Date
    Oct 2007
    Answers
    88

    Smile Re: pointers and union?

    Quote Originally Posted by amar1_001 View Post
    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 hold type; //union variable of hold type
    union hold save [10];// arry type
    union hold *p;// pointer
    pointer to structure
    ordinary pointer
    double pointer


  3. #3
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    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


  4. #4
    Junior Member
    Join Date
    Jul 2007
    Answers
    2

    Thumbs up Re: pointers and union?

    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.


  5. #5
    Contributing Member
    Join Date
    Dec 2007
    Answers
    46

    Re: pointers and union?

    Quote Originally Posted by amar1_001 View Post
    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
    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.


  6. #6
    Junior Member
    Join Date
    Nov 2008
    Answers
    1

    Re: pointers and union?

    What is the difference between const voletile and voletile ?


  7. #7
    Junior Member
    Join Date
    Nov 2009
    Answers
    2

    Re: pointers and union?

    Const volatile : your object cannot modify it but any external process could


  8.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact