Is it possible to redefine a c++ keyword using #define?
#ifdef int
#undef int
#define int 2
#endif
int main(){
//Do something with int
}
I
You can, but you shouldn't.
In your examples, int doesn't get redefined, since it's wrapped in #ifdef int. That means "only do this if there's already a preprocessor macro called int", and there isn't.
If you just wrote #define int 2, then all occurrences of int would be replaced by 2; but then your code wouldn't compile since 2 main() {cout<<2;} is nonsense.
#undef will not remove a keyword from the language; it only removes preprocessor macros previously defined using #define.