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?
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.
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)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With