Primitive vs non-primitive data structureData structure means organizing the data in the memory. The data can be organized in two ways either linear or non-linear 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 non-primitive data structure is a type of data structure which is a user-defined 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 non-primitive 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 non-primitive data structure, it is categorized into two parts such as linear data structure and non-linear 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. Non-linear data structure is a kind of random type of data structure. The non-linear data structures are Tree and Graph. Let's understand the differences between the primitive and non-primitive data structure. ![]()
Primitive data structurePrimitive data structure is a data structure that can hold a single value in a specific location whereas the non-linear 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:
Non-primitive data structureThe non-primitive data structure is a kind of data structure that can hold multiple values either in a contiguous or random location. The non-primitive data types are defined by the programmer. The non-primitive data structure is further classified into two categories, i.e., linear and non-linear 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
|