linked list in C II

ok,,

I have seomthing of this format

this represents my node format, and I have another structure defined within this struture and say one of the declarations of the structure xyz is int k

As far as i remember C , I can call the value of the variable k as below right?

typedef struct
{
struct xyz
} node ;


node ->xyz.a ?

Replies

  • pradeep_agrawal
    pradeep_agrawal
    @Durga, few corrections.

    The declaration that you have done is declaration of a new data type and not a variable (as you are using typedef). Also it has some syntax errors.

    If we have to define a struct x which contains variable var_y of another struct y which itself contains a variable int z, then the declaration will look like:

    struct x {
      struct y {
        int z;
      } var_y;
    };
    
    or
    struct y {
       int z;
    };
     
    struct x {
      struct y var_y;
    };
    
    The point to note in first case is that if you declare only struct and not a variable of that struct, compiler will throw a warning that the declaration does not declare anything. Also logically such declaration does not make sense.

    A variable of struct x can be declared as:

    struct x var_x;

    And the internal variable z can be accessed as:
    var_x.var_y.z.

    Please refer below example for the details specified above:
    #include "stdio.h"
    
    struct x {
      struct y {
        int z;
      } var_y;
    };
    
    int main() {
      struct x var_x = { 0 };
      printf("z = %d\n", var_x.var_y.z);
      return 0;
    }
    
    -Pradeep
  • durga ch
    durga ch
    ahem!Thanks!
    My deadline has passed for project and I am not done with it, I submitted a project which is 80% done. Planning to resume it in holidays as a learning program, so I will pop up with many such syntax related questions 😉

    thanks again

You are reading an archived discussion.

Related Posts

Hi all, Yesterday I was going through some stuff and found that behavior of floating point numbers in most of the programming languages is platform dependent at times. Is there...
Hey, hi to all, Just want to know from my fellow Mechanical Engineers, How do you bridge the gap between Thoery and Practice? What do you do on the Job,...
A lawyer's son finishes his law degree and gets a job in the same court where his father has been working over many years. On the very first day in...
just want to know what does this branch deal with?? also few details abt what is instumentation and control eng?
Dear CEans we all know satellites are very much relied these days for communication. I thought it would be a good thing if we can help each other solving all...