Totie
Totie

Reputation: 21

structure member syntax

I am unable to access member of a structure

The code is as follows :

int main()
{

      typedef struct tempA
       {
         int a;
        }tempa;


      typedef struct tempB
      {
        tempa **tA;
       }tempb;

     tempb.(*tA)->a =5;
     printf("\n Value of a : %d",tempb.(*tA)->a);

}

I tried to access it using tempb.(*tA)->a; but I am getting syntax error:

error: expected identifier before ‘(’ token 

What is the correct syntax to access int a?

Thanks in advance

Upvotes: 0

Views: 188

Answers (1)

Michael Madsen
Michael Madsen

Reputation: 55009

The right syntax is (*tempb.tA)->a. You want to dereference tempb.tA to get a pointer to a tempA, then dereference that pointer to access the a member.

Upvotes: 7

Related Questions