c - Nested structures and Typedef -
I am trying to print no_routes through the structure and typedef in the CO. But there is a mistake of the code segment below
typedef structure RDI {int no_routes; } RD; Structure os-class {RD OS_RDI [10]; } * OS_CL; Zero Initiate_CL () {OS_CL- & gt; Os_rdi [0] .no_routes = 10; } Main () {Initiate_CL (); // printf ("CL% d", OS_CL-> os_rdi [0] .no_routes); }
User types are typed to give a name for typed data type. For example, you can type typed with the structure to define a new data type, and then use that data type to define the structure variable directly as follows:
You are using OS_CL
(which is the indicator), but for this allocated memory has not been done.
zero initialize_CL () {OS_CL = malloc (sizeof (Os_class)); & Lt; - Allocation of OS_CL- & gt; OS_RDI [0] .no_routes = 10; }
After use to avoid memory leak, make sure you de-allocate memory with free
.
Comments
Post a Comment