Home C C++ Java Python Perl PHP SQL JavaScript Linux Online Test

Home » C++ » Solved Program » Iinitialize const variables of any class

How to initialize const variables of any class in C++

#include <iostream>
using namespace std;

class circle{
	double r;
	const double pi;
	circle(double r) : pi(3.14159){
	double area (){
		return pi*(pow(r,2));
	double circumference (){
		return 2*pi*r;

int main(){
	circle c=circle(6.70);
	cout<<"area of circle :"<<c.area()<<endl;
	cout<<"circumference of circle :"<<c.circumference ()<<endl;
	return 0;