Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,023 questions

51,974 answers

573 users

How to define nested structures in C

1 Answer

0 votes
#include <stdio.h>
 
typedef struct
{
   int data;
} info;

typedef struct
{
   info age;
   float salary;
} worker;
 
int main(void)
{
    worker w;
    
    printf("Enter Age: ");
    scanf("%d", &w.age.data);
    printf("Enter Salary: ");
    scanf("%f", &w.salary);

    printf("age = %d\n", w.age.data);
    printf("salary = %.2f\n", w.salary);
 
    return 0;
}

/*
run:
 
Enter Age: 35
Enter Salary: 4593
age = 35
salary = 4593.00

*/


answered Oct 7, 2014 by avibootz
...