Thread: Array of pointers to structs

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    14

    Array of pointers to structs

    I am kinda confused with this.

    Code:
    typedef struct{
        char firstName[SIZE];
        char lastName[SIZE];
    } fullName;
    
    
    typedef struct{
        long unsigned int codeName;
        fullName *name;
        short unsigned int matchCode;
    } registers;
    
    
    
    
    typedef struct{
        registers *rgs[SIZE];
        int size;
    } matches;
    With the code above, i created a struct called matches that 'contains' an array of pointers to registers?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,710
    Yes, that's right.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2020
    Posts
    14
    And if i do this:
    Code:
    registers rg;
    matches mtchs;
    rg.codeName = 123;
    rg.matchCode = 123;
    strcpy(rg.name->fullName, "123");
    strcpy(rg.name->lastName = "123");
    
    mtches.rgs[0] = & rg;
    its like i am setting the first pointer to the struct rg?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,710
    Yes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of pointers to structs
    By MedicineMan25 in forum C Programming
    Replies: 4
    Last Post: 09-23-2017, 11:10 AM
  2. Replies: 5
    Last Post: 12-20-2011, 09:43 PM
  3. Array of Pointers to Structs
    By I BLcK I in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2008, 11:03 PM
  4. Array of pointers to structs
    By lpmrhahn in forum C Programming
    Replies: 1
    Last Post: 04-17-2004, 09:46 AM
  5. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 07:13 AM

Tags for this Thread