Program to check if an Array is Palindrome or not using STL in C++ Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Given an array, the task is to determine whether an array is a palindrome or not, using STL in C++. Examples: Input: arr[] = {3, 6, 0, 6, 3} Output: Palindrome Input: arr[] = {1, 2, 3, 4, 5} Output: Not Palindrome Approach: Get the reverse of the Array using reverse() method, provided in STL.Initialise flag to unset int flag = 0.Loop the array till size n and check if the original array and the reversed array are same. If not set flag = 1After the loop has ended, If flag is set the print "Not Palindrome" else print "Palindrome" Below is the implementation of above Approach: CPP // C++ program to check if an Array // is Palindrome or not using STL #include <bits/stdc++.h> using namespace std; void palindrome(int arr[], int n) { // Initialise flag to zero. int flag = 0; // Create another array // to store the original array int arr2[n]; memcpy(arr2, arr, n * sizeof(int)); // Reverse the array reverse(arr, arr + n); // Check if the array is Palindrome for (int i = 0; i < n; i++) if (arr[i] != arr2[i]) { flag = 1; break; } // Print the result if (flag == 0) cout << "Palindrome\n"; else cout << "Not Palindrome\n"; } int main() { // Get the array int arr[] = { 1, 2, 3, 2, 1 }; // Compute the size int n = sizeof(arr) / sizeof(arr[0]); palindrome(arr, n); return 0; } Output:Palindrome Time complexity: O(n)Auxiliary space: O(n) Related Articles: https://www.geeksforgeeks.org/dsa/program-to-check-if-an-array-is-palindrome-or-not/https://www.geeksforgeeks.org/dsa/program-to-check-if-an-array-is-palindrome-or-not-using-recursion/ Create Quiz Comment C code_r Follow 2 Improve C code_r Follow 2 Improve Article Tags : C++ Programs C++ STL palindrome cpp-array +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like