What is the difference between scalar types and aggregate types in C?

I read a book called Pointers On C, in this book there is a type called scalar types.
I know that arithmetic types and pointer types are collectively called scalar types, but I want to know what is the difference between the types of the scalar type and the type of aggregate and what they use?

+5
source share
4 answers

C11-Β§6.2.5 Types (p21):

Arithmetic types and pointer types are collectively called scalar types. Array types and structures are collectively called aggregate types. 46)

Scalar data types can contain only one data element, while aggregate types can contain more than one data element.

int a; //Scalar Type char c; //Scalar Type float *p; //Scalar Type char str[10]; //Aggregate Type struct s{ int a; float b[5]; } ss; //Aggregate Type 

46) Note that the aggregate type does not include the union type, because an object with the union type can contain only one element at a time.

+7
source

Since the aggregation of words itself assumes that the types of aggregation are composed of other types.

Aggregation types C use array types and structures.

Note that the type of aggregation may include a different type of aggregation.

The following is an example of aggregation types.

 #include <stdio.h> int main( void ) { struct TLine { struct TPoint { int x; int y; } first, second; } lines[10] = { [0] = { { 0, 0 }, { 10, 10 } } }; printf( "lines[%d].first = { %d, %d }, lines[%d].second = { %d, %d }\n", 0, lines[0].first.x, lines[0].first.y, 0, lines[0].second.x, lines[0].second.y ); } 

Program exit

 lines[0].first = { 0, 0 }, lines[0].second = { 10, 10 } 

A TLine structure is an aggregation type that contains another definition of the aggregation type of a struct TPoint . And lines is the object of yet another type of aggrefation - the TLines array.

+1
source

The Internet can be your friend! But a scalar type is a type for which arithmetic exists for its values ​​(integers, floats, pointers), and the aggregate type is just a type for which values ​​are the roots of values, i.e. A collection of values, for which there is no natural arithmetic (for example, a person described by his name and age, you cannot add or multiply two persons ...).

0
source

Taken from here :

C Scalar

"C Scalar Data Types" displays C scalar data types, providing their size and format. Aligning a scalar data type is equal to its size. Scalar Alignment shows scalar alignments that apply to individual scalars and scalars that are elements of an array or members of a structure or union. Wide characters are supported (character constants with the L prefix). The size of each wide character is 4 bytes.

C Aggregate data types

Aggregate data type consists of one or more types of scalar data. You can declare the following aggregate data types:

  • Array

  • Union

  • Struct

It was just a brief definition, but the link I gave has great content.

To make this clearer, here is a block diagram:

enter image description here

Here is an even more detailed block diagram:

enter image description here

0
source

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


All Articles