Useful defines!

Правка en1, от Meron3r, 2024-02-13 12:27:49

Macros or also known as #define in c++ are very useful, but it takes a while to think of some great one that will save you a LOT of time, or a little, but it still makes it look better. Like, I was a python programmer and then when I switched to c++, I wasn't used to writing string, so I made a define like this:

#define str string

Here are my personal macros

#define sz size
#define yes cout << "YES"
#define no cout << "NO"
#define str string
#define ll long long
#define ull unsigned ll
#define uint unsigned int
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define vc vector
#define vci vector<int>
#define vcstr vector<str>
#define vcll vector<ll>
#define vcc vector<char>
#define fast ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define fi first
#define se second
#define be begin()
#define en end()

When you start solving a problem, you usually write long pieces of code. #define allows you to shorten and simplifie any ones code. If you want to make a macro for yourself you need to know how to make one first:

// here  we make a define for long long:
#define ll long long

After you do that you can use it anytime you want, for example:

ll a = 98210;

vector<ll> t;

unsigned ll factorial(x) {

if (x == 1 || x == 0) return 1;

else return x * factorial(x - 1);

}

Remember, defines vary from people, you can even get inspired by other peoples #define's too! ask a friend about his defines, they might also be useful for you too!

Теги #define, define, macros, macro

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Meron3r 2024-02-13 12:27:49 1629 Initial revision (published)