linked list in C II

durga ch

durga ch

@durga-TpX3gO Oct 22, 2024
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

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • pradeep_agrawal

    pradeep_agrawal

    @pradeep-agrawal-rhdX5z Jun 19, 2009

    @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

    @durga-TpX3gO Jun 21, 2009

    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