0
#include<stdio.h>
#include<stdlib.h>
int main(){
     struct nodeout
     {
      int out;
      struct nodein{int in; }; 
     };

     struct nodeout* p;
     p=(struct nodeout*)malloc(sizeof(struct nodeout));
     p->out=10;

     printf("%d",p->out);
 } 

..Here is my code..How can I initialize the variable 'in' which is inside the structure nodein?

3
  • Kindly show your research / debugging effort so far. Please read How to Ask page first. Commented Jul 9, 2017 at 6:22
  • prog.c:7:30: error: declaration does not declare anything Commented Jul 9, 2017 at 6:26
  • Give it a name. struct nodein{int in; }; --> struct nodein{int in; } s_in; then p->s_in.in = 42; Commented Jul 9, 2017 at 6:29

1 Answer 1

1

You did define struct nodein but did not define the nodein member for struct nodeout.

Do as following:

#include<stdio.h>
#include<stdlib.h>

int main(){
    struct nodeout
    {
        int out;
        struct nodein {int in; } node_in; 
    };

    struct nodeout* p;
    p = (struct nodeout*)malloc(sizeof(struct nodeout));
    p->out = 10;
    p->node_in.in = 5

    printf("%d %d”, p->out, p->node_in.in);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.