Interview Questions on C C++

Home  |  About Us  |  Contact
View Questions Contribute Training Misc..

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;