Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have read a book called "Pointers On C". In that 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 scalar type and aggregate type and what occasion use them?

like image 209
shengfu zou Avatar asked Mar 01 '16 12:03

shengfu zou


People also ask

What is a scalar type in C?

C Scalar. “C Scalar Data Types” lists C scalar data types, providing their size and format. The alignment of a scalar data type is equal to its size. “Scalar Alignment” shows scalar alignments that apply to individual scalars and to scalars that are elements of an array or members of a structure or union.

What is aggregate data type in C?

C has two kinds of aggregate type: arrays and structures. To define an aggregate type, it is helpful to first define a scalar type. A scalar type is a type that contains a single value. In C, scalar types are: arithmetic types (integers and floating point numbers)

What is an aggregated data type?

Aggregate Data Types. Aggregate data type also refer to complex data structure, is any type of data that can be referenced as a single entity, and yet consists of more than one piece of data. This data type is used to keep all related data together in a way that emphasizes the relationship of the data.

What is a scalar data type?

Scalar data are characterized by the fact that they contain a single value. Thus, they are the building blocks of any information that your perl program will store or manipulate. There are two main types of scalar data in perl: string and numeric.


1 Answers

C11-§6.2.5 Types (p21):

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

Scalar data types can hold only single data item while aggregate types can hold more than one data items.

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 aggregate type does not include union type because an object with union type can only contain one member at a time.

like image 188
haccks Avatar answered Sep 28 '22 07:09

haccks