Primitive vs nonprimitive data structureData structure means organizing the data in the memory. The data can be organized in two ways either linear or nonlinear way. There are two types of data structure available for the programming purpose:
Primitive data structure is a fundamental type of data structure that stores the data of only one type whereas the nonprimitive data structure is a type of data structure which is a userdefined that stores the data of different types in a single entity. In the above image, we can observe the classification of the data structure. The data structure is classified into two types, i.e., primitive and nonprimitive data structure. In the case of primitive data structure, it contains fundamental data types such as integer, float, character, pointer, and these fundamental data types can hold a single type of value. For example, integer variable can hold integer type of value, float variable can hold floating type of value, character variable can hold character type of value whereas the pointer variable can hold pointer type of value. In the case of nonprimitive data structure, it is categorized into two parts such as linear data structure and nonlinear data structure. Linear data structure is a sequential type of data structure, and here sequential means that all the elements in the memory are stored in a sequential manner; for example, element stored after the second element would be the third element, the element stored after the third element would be the fourth element and so on. We have different linear data structures holding the sequential values such as Array, Linked list, Stack, Queue. Nonlinear data structure is a kind of random type of data structure. The nonlinear data structures are Tree and Graph. Let's understand the differences between the primitive and nonprimitive data structure.
Primitive data structurePrimitive data structure is a data structure that can hold a single value in a specific location whereas the nonlinear data structure can hold multiple values either in a contiguous location or random locations The examples of primitive data structure are float, character, integer and pointer. The value to the primitive data structure is provided by the programmer. The following are the four primitive data structures:
Nonprimitive data structureThe nonprimitive data structure is a kind of data structure that can hold multiple values either in a contiguous or random location. The nonprimitive data types are defined by the programmer. The nonprimitive data structure is further classified into two categories, i.e., linear and nonlinear data structure. In case of linear data structure, the data is stored in a sequence, i.e., one data after another data. When we access the data from the linear data structure, we just need to start from one place and will find other data in a sequence. The following are the types of linear data structure:
For example: int a[6] = {1,2,3,4,5,6}; The above example is an array that contains the integer type elements stored in a contiguous manner.
String data structure: In the above example, the length of the string is 17 as the last character is the NULL character which denotes the termination of the string. Char Representation: In the above example, the length of the string is 16 as it does not have any NULL character as the last character to denote the termination.
Next TopicData types vs data structure
