Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define equivalent in c++

Tags:

c++

g++ 4.7.2

Hello,

I am coming from C89 and now I am doing c++ using g++ compiler.

Normally I do things like this:

#define ARR_SIZE 64
#define DEVICE "DEVICE_64"

What is the equivalent of doing this in C++?

Many thanks for any suggestions,

like image 871
ant2009 Avatar asked Dec 15 '12 11:12

ant2009


3 Answers

#define is there in C++. So you can write the same code. But for constant quantities like this, it is better to use the const keyword.

const int ARR_SIZE = 64;
const std::string DEVICE("DEVICE_64");
like image 185
Manoj R Avatar answered Oct 12 '22 11:10

Manoj R


You can use const in place of #define

  const int ARR_SIZE = 64;
  const char DEVICE[] = "DEVICE_64";
like image 23
Rahul Tripathi Avatar answered Oct 12 '22 11:10

Rahul Tripathi


You can define constants using the const keyword:

const int ARR_SIZE = 64;
const char DEVICE[] = "DEVICE_64";
like image 34
wilx Avatar answered Oct 12 '22 10:10

wilx