By 25/02/2014 5 Comments

Constants in C++

Constants are expressions with a fixed value.

Defined constants (#define)

You can define your own names for constants that you use very often without having to resort to memory- consuming variables, simply by using the #define preprocessor directive. Its format is:

#define identifier value

Code Snippet

#include <iostream>
using namespace std;

#define PI 3.14159
#define NEWLINE '\n'

void main ()
{
double radius=5.0;	// radius
double circle;

circle = 2 * PI * radius;
cout << circle;  cout << NEWLINE;

getch();
}

Declared constants (const)

With the const prefix you can declare constants with a specific type in the same way as you would do with a variable. Here is the Code Snippet for it.

const int width = 1000;
const char tabulator = '\t';





Next Tutorial →


← Previous Tutorial


Posted in: C++ Basics

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .