Is it accurate to consider structure as a data type?

Based on my understanding of data types: computers can only store 0 and 1, it cannot store a negative number, real number, character, etc. Thus, data types were created to represent (encode) each of these data types as a set of 0s and 1s, and then decode it when necessary.

But what about structure:

struct Student
{
    int age;
    float gpa;
};

Student s1; s1.age = 17; s1.gpa = 3.42;
Student s2; s2.age = 16; s2.gpa = 3.64;

This is like an object, so I don't need to write:

int student1_age = 17;
float student1_gpa = 3.42;

int student2_age = 16;
float student2_gpa = 3.64;

So, is it correct to consider a Studentdata type in the same way that a floatis a data type?

+4
source share
6 answers

: 0 1s, , , , .. , () 0s 1s, .

. , , int float - , ( HW, ). , .. , , .

struct ( ). C (- , ); , . ....

+2

. , structure , .

, , ​​ . c, signed.

char

structure - , .

, , . ; .

+2

int float . struct , -, . , struct - , , .

+1

- , . struct. .

struct movie
{
  string name;
  string release_date;
};

struct movie_store
{
  movie *ptr;
}

* ptr, , , ,

0
struct X{
     char a, b;
     int count;
     float n;
};

struct book;

, . Struct - ,

0

.

- , , real, integer Boolean, ; , ; ; . ( Wikipedia)

, , () , - ( ) , . - HTML CSS: - , ( , ).

, , , .

One difference between the structures / arrays and base types ( int, float, boolean, charetc.) is that the struct / array can also tell us about the connection of the base type (s) inside them. All variables within the structure are related to the structure and should be considered as a whole. An array tells you that all of its atoms are parallel. But a variable of a basic type simply means that an autonomous, simple mathematical or logical value is stored there.

0
source

Source: https://habr.com/ru/post/1568511/


All Articles