#define cpp code example
Example 1: define in cpp
#include <iostream>
#define LIMIT 5
int main()
{
for (int i = 0; i < LIMIT; i++) {
std::cout << i << "\n";
}
return 0;
}
Example 2: define c++
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ar array
#define ll long long
#define pb push_back
Example 3: #define in cpp
#include <iostream>
using namespace std;
#define CONSTANT 2.71828
int main () {
cout << "Declared constant: " << CONSTANT << endl;
return 0;
}
Example 4: c++ what is #define
#include <iostream>
#define SIZE 5
#define MacroInt int
#define getmax(a,b) ((a)>(b)?(a):(b))
int main(){
MacroInt myIntAsMacro = 7;
std::cout<< getmax(SIZE, myIntAsMacro);
}