"const in c++" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "const in c++" answered properly. Developers are finding an appropriate answer about const in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like const in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on const in c++. 

const in c++

By Alive AngelfishAlive Angelfish on Jun 17, 2020
// 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;
}

Add Comment

7

const c++

By BreadCodeBreadCode on Apr 08, 2021
//Syntax: const Class_Name Object_name;
const int MAXN = 1e5 + 5;
const long long mod = (long long)1e9 + 7;

Add Comment

0

c++ constant

By Phil the ice cream manPhil the ice cream man on Nov 10, 2020
#define LENGTH 10   
#define WIDTH  5
#define NEWLINE '\n'

Add Comment

-1

All those coders who are working on the C++ based application and are stuck on const in c++ can get a collection of related answers to their query. Programmers need to enter their query on const in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about const in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of const in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "const in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like const in c++ resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "const in c++"

View All C++ queries

C++ queries related to "const in c++"

Browse Other Code Languages

CodeProZone