Структуры. Основы структуры

Слайд 2

основы структуры struct cmplx{ double a; double b; };

основы структуры

struct cmplx{
double a;
double b;
};

Слайд 3

передача структуры в качестве аргумента в функцию double maxmod (struct cmplx

передача структуры в качестве аргумента в функцию

double maxmod (struct cmplx

z, struct cmplx w) {
double modz = z.a * z.a + z.b * z.b;
double modw = w.a * w.a + w.b * w.b;
if (modz >= modw) {
return modz;
}
else {
return modw;
}
}
int main(){
cmplx q,r;
q.a = 1;
q.b = 2;
r.a = 3;
r.b = 4;
printf("%f\n", sqrt(maxmod(q,r)));
return 0;
}
Слайд 4

другие примеры структур struct student { char name[20]; char surname[20]; int year_of_birth; double rating; };

другие примеры структур

struct student {
char name[20];
char surname[20];
int year_of_birth;


double rating;
};
Слайд 5

другие примеры структур struct polk{ char name[20]; int rod; double attack;

другие примеры структур

struct polk{
char name[20];
int rod;
double attack;
double

defend;
int velos;
int quantity;
};
Слайд 6

другие примеры структур2 struct student { char name[20]; char surname[20]; int year_of_birth; double rating; };

другие примеры структур2

struct student {
char name[20];
char surname[20];
int year_of_birth;


double rating;
};
Слайд 7

структура как возвращаемые значение из функции struct cmplx summa (struct cmplx

структура как возвращаемые значение из функции

struct cmplx summa (struct cmplx

z, struct cmplx w) {
cmplx s;
s.a = z.a + w.a;
s.b = z.b + w.b;
return s;
}
int main(){
cmplx q,r,s;
q.a = 1;
q.b = 2;
r.a = 3;
r.b = 4;
s = summa(q,r);
printf("%.0f+%.0fi\n", s.a, s.b);
return 0;
}
Слайд 8

typedef и его использование в разработке «Оператор переопределения типов typedef вводит

typedef и его использование в разработке

«Оператор переопределения типов typedef вводит

синоним для существующего типа, например
typedef unsigned char BYTE;
BYTE b; // b – типа unsigned char»
Источник: https://prog-cpp.ru/c-typedef/
#include 
#include 
typedef struct Books {
  char  title[50], author[50], subject[100];
  int   book_id;
} Book;
int main( ) {
  Book book;
  strcpy( book.title, "C Programming");
  strcpy( book.author, "Nuha Ali");
  strcpy( book.subject, "C Programming Tutorial");
  book.book_id = 6495407;
  printf( "book title : %s\n", book.title);
  printf( "book author : %s\n",book.author);
  printf( "book subject : %s\n", book.subject);
  printf( "book book_id : %d\n", book.book_id);
  getchar(); getchar();
  return 0;
}
Источник: [1]
Слайд 9

указатели на структуры «Указатель на структуру создаётся как обычно. Отличие заключается

указатели на структуры

«Указатель на структуру создаётся как обычно. Отличие заключается

в том, что можно обращаться к полям структуры через указатель с помощью операции "стрелка" (минус + больше)». 
typedef struct User {
    char *login;
    char *password;
    int id;
} User;
void jsonUser(User *user) {
    printf("{id: %d, login: \"%s\", password: \"%s\"}\n",
            user->id, user->login, user->password);
}
Источник: [2]
Слайд 10

Список использованных источников 1. https://prog-cpp.ru/c-typedef/ 2. http://learnc.info/c/structures.html#pointer_to_structure

Список использованных источников

1. https://prog-cpp.ru/c-typedef/
2. http://learnc.info/c/structures.html#pointer_to_structure