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 9131525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:09:19+00:00 2026-06-17T08:09:19+00:00

typedef struct { struct { double i1, i2; } EXP; struct { double i1,

  • 0
typedef struct {

   struct {
      double i1, i2;
   } EXP;

   struct {
      double i1, i2;
   } SIN;

   struct {
      double i1, i2;
   } PULSE;

   struct {
      double *i1, *i2;
   } PWL;
} TRANS;

struct term {
   TRANS trans;
   struct term *nxt;
};

int main() {
   struct term *look;
}

I have the above structs and the pointer look to the struct term. Could someone tell me how to dereference pointer i1 inside struct PWL?

I’ve tried this:

*(look->trans.PWL.i1)

but it produces segmentation fault.

Thanks in advance!

  • 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-17T08:09:20+00:00Added an answer on June 17, 2026 at 8:09 am

    The segmentation fault is because you allocated a pointer, but did not create memory for the pointer to point at. Once you do that, then *(look->trans.PWL.i1) is indeed how to access that field in the inner struct.

    You need to allocate memory for the struct, and all references within.

    struct term *look = malloc(sizeof(struct term));
    look->trans.PWL.i1 = malloc(sizeof(double));
    look->trans.PWL.i2 = malloc(sizeof(double));
    

    And naturally you need to reverse the process with calls to free when you are done.

    free(look->trans.PWL.i2);
    free(look->trans.PWL.i1);
    free(look);
    

    Or, perhaps i1 and i2 are meant to point to values that are allocated elsewhere then it would look like this:

    struct term *look = malloc(sizeof(struct term));
    look->trans.PWL.i1 = &look->trans.EXP.i1;
    look->trans.PWL.i2 = &look->trans.EXP.i2;
    

    And to deallocate you just free look. Remember to pair each successful call to malloc with a call to free.

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

Sidebar

Related Questions

For example in C I have structure: typedef struct { int number; double x1;
I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1;
I have a struct typedef struct { int id; string name; string address; string
I have a structure typedef struct store { char name[11]; int age; } store;
I have created following structure 'data' in C typedef struct data { double *dattr;
typedef struct Complex{ double real; int img; } Complex; I've seen people use it
Say I have a struct like the following ... typedef struct { int WheelCount;
I have a short piece of code like this: typedef struct { double sX;
typedef struct Matrix { double * matrix; int sizex; int sizey; }Matrix; int nn
I have Struct like these typedef struct sample { double x, double y, double

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.