Check out example codes for "const in c++". It will help you in understanding the concepts better.

Code Example 1

// various versions of const are explained below
#include <iostream>
class Entity {
private:
	int m_X, m_Y;
	mutable int var; // can be modified inside const menthods
	int* m_x, *m_y;// * use to create pointer in one line
public:
	int GetX() const // cant modify class variables
	{
		//m_X = 4;//error private member can't be modified inside const method
		var = 5; // was set mutable
		return m_X;
	}
	int Get_X()// will modify class 
	{
		return m_X;
	}
	const int* const getX() const  // returning a pointer that cannot be modified & context of pointer cannot be modified
	{
		//m_x = 4;
		return m_x;
	}
	void PrintEntity(const Entity& e) {
		std::cout << e.GetX() << std::endl;
	}
};
int main() {
	Entity e;
	const int MAX_AGE = 90;
   // MAX_AGE =100; error const var is stored in read only section in memory and we can't write to that memory
	//  int const* a = new int; is same as const int* a = new int ;////but you can't change the context of pointer but can reassign it to a pointer something else
	int * const a = new int; //can change the context of pointer but can't reassign it to a pointer something else
   *a = 2;
    a = &MAX_AGE;// error can't change it to ptr something else
   	std::cout << *a << std::endl;
	a =(int*) &MAX_AGE;
	std::cout << *a << std::endl;
}

Code Example 2

// CPP program to count words in a string 
// using stringstream. 
#include <bits/stdc++.h> 
using namespace std; 
  
int countWords(string str) 
{ 
    // breaking input into word using string stream 
    stringstream s(str); // Used for breaking words 
    string word; // to store individual words 
  
    int count = 0; 
    while (s >> word) 
        count++; 
    return count; 
} 
  
// Driver code 
int main() 
{ 
    string s = "geeks for geeks geeks "
               "contribution placements"; 
    cout << " Number of words are: " << countWords(s); 
    return 0; 
}

Learn ReactJs, React Native from akashmittal.com