struct-typedef-enum

title: "courses/c-course - struct-typedef-enum.md"

- **fileName**: struct-typedef-enum
- **Created on**: 2024-06-08 10:07:04

struct is custom data types

struct Student {
	char username[13]; // must adding the size for array 
	int age;
}

struct Student student1 = { "yossef", 20};
printf("studnet name is : %s", student1.name);

typedef is better way to type struct :

typedef struct {
char username[]; // must adding the size for the array 
int age;
}User;

User user1 = { "yossef", 20};
printf(user1.name);

can use struct inside another one

example

typedef struct {
  char nighberhead[10];
  char city[20];
  int partment;
}Address;

typedef struct {
  char fname[10];
  char lname[10];
}Username;

typedef struct {
  int age;
  int id;
  Username username;
  Address address;
} User;


int main() {
  User user1 = { 20, 202202719, "yossef", "sabry", "bader", "eltour south sinal", 1 };
  printf("%s \n", user1.username.fname);
  printf("%s \n", user1.address.city);
  return 0;
};

Enum for make object of constant :

enum Status {
	Danger = "danger",
	Safe = "Safe",
};
enum Days {
	sun = 1, mon = 2, thisday = 3, wenthday = 4 
};
enum Status status = Danger;

continue:[[]]
before:array.md