Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:29:15+00:00 2026-06-02T17:29:15+00:00

At the moment I have the following code: typedef struct _hexagon { int *vertice[6];

  • 0

At the moment I have the following code:

typedef struct _hexagon {
    int *vertice[6];
    int *path[6];
    int resourceType;
} hexagon;


typedef struct _game {
    hexagon hexagons[5][5];
} Game;

and in the main I have:

Game g;
// This is the line that fails
g.hexagons[0][0].vertice[0] = 0;

This compiles fine but gives a segmentation fault. I have tried many variations, such as

g.hexagons[0][0].*vertice[0] = 0;

which doesn’t compile. How do I access a pointer’s memory from within a struct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:29:16+00:00Added an answer on June 2, 2026 at 5:29 pm

    As vertice is a array-of-pointes-to-integers, to access vertice[0], you need to do *g.hexagons[0][0].vertice[0]

    Sample program:

    #include <stdio.h>
    
    typedef struct _hexagon {
        int *vertice[6];
        int *path[6];
        int resourceType;
    } hexagon;
    
    
    typedef struct _game {
        hexagon hexagons[5][5];
    } Game;
    
    int main()
    {
        int i1 = 1;
        int i2 = 2;
        int i3 = 3;
        int i4 = 4;
        int i5 = 5;
        int i6 = 6;
    
        Game g;
        g.hexagons[0][0].vertice[0] = &i1;
        g.hexagons[0][0].vertice[1] = &i2;
        g.hexagons[0][0].vertice[2] = &i3;
        g.hexagons[0][0].vertice[3] = &i4;
        g.hexagons[0][0].vertice[4] = &i5;
        g.hexagons[0][0].vertice[5] = &i6;
    
        printf("%d \n", *g.hexagons[0][0].vertice[0]);
        printf("%d \n", *g.hexagons[0][0].vertice[1]);
        printf("%d \n", *g.hexagons[0][0].vertice[2]);
        printf("%d \n", *g.hexagons[0][0].vertice[3]);
        printf("%d \n", *g.hexagons[0][0].vertice[4]);
        printf("%d \n", *g.hexagons[0][0].vertice[5]);
    
        return 0;   
    }
    

    Output:

    $ gcc -Wall -ggdb test.c 
    $ ./a.out 
    1 
    2 
    3 
    4 
    5 
    6 
    $ 
    

    Hope it helps!


    UPDATE: as pointed out by Luchian Grigore

    The reason for the segmentation fault is explained by the following small program. In short, you are de-referencing a NULL pointer.

    #include <stdio.h>
    
    /*
    int *ip[3];
    +----+----+----+
    |    |    |    |
    +----+----+----+
       |    |    |
       |    |    +----- points to an int *
       |    +---------- points to an int *
       +--------------- points to an int *
    
    ip[0] = 0;
    ip[1] = 0;
    ip[2] = 0;
    
    +----+----+----+
    |    |    |    |
    +----+----+----+
       |    |    |
       |    |    +----- NULL
       |    +---------- NULL
       +--------------- NULL
    
    *ip[0] -> dereferencing a NULL pointer ---> segmantation fault
    */
    
    int main()
    {
        int * ip[3];
        ip[0] = 0;
        ip[1] = 0;
        ip[2] = 0;
    
        if (ip[0] == NULL) {
            printf("ip[0] is NULL \n");
        }
    
        printf("%d \n", *ip[0]);
        return 0;
    }
    

    Now you can co-relate int *ip[] with your g.hexagons[0][0].vertice[0]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have the following code which works fine. label = new
I have the following code: http://jsfiddle.net/uRCL2/1 At the moment the result is shown in
The following code summarizes the problem I have at the moment. My current execution
I have the following code: public IDictionary<string, int> GetCountByDate(DateTime fromDate, DateTime toDate) { var
I have the following code at the moment: $ip = '195.72.186.157'; $xmlDoc = new
So I have the following code at the moment: <form action=> <div id=term><select name=s2
Okay, at the moment I have the following in my model: has_many :current_monitorings, :class_name
I just started using django for development. At the moment, I have the following
I have the following code: $q1 = $_POST[q1]; $q2 = $_POST[q2]; $q3 = $_POST[q3];
I have the following code to build a custom taxonomy for my portfolio: add_action(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.