In C++, non-primitive data types are data structures defined by the programmer or provided by the language library. Here are some commonly used non-primitive data types in C++ along with examples:
And Other Data Types such as Linked Lists, Queues, Trees, etc. are Non Primitive Data Types
#include <iostream>
#include <map> // For using map
using namespace std;
int main(){
// Array
int arr[5] = {1, 2, 3, 4, 5};
// String
string name = "John Doe";
// Structure
struct student{
int roll_no;
string name;
float marks;
};
// Class
class rectangle{
int length, width;
public:
int area(){
return length * width;
}
};
// Pointer
int x = 10;
int *ptr = &x;
// Dynamic Array
int *dynamic_arr = new int[5];
// Map
// Use #include<map> for using map
map<string, int> m;
}