Last active
December 22, 2020 05:46
-
-
Save domiyanyue/61fd064e16eca11dd74ca39c7cb0eda1 to your computer and use it in GitHub Desktop.
example -D macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#ifndef SIZE_ARRAY | |
#define SIZE_ARRAY 4 | |
#endif | |
int main(){ | |
int array[SIZE_ARRAY] = {0}; | |
std::cout << "num of elements: " << sizeof(array)/sizeof(array[0]) << "\n"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpp_tutorial# g++ macro_example.cpp -o a | |
cpp_tutorial# ./a | |
num of elements: 4 | |
cpp_tutorial# g++ macro_example.cpp -o a -DSIZE_ARRAY | |
cpp_tutorial# ./a | |
num of elements: 1 | |
cpp_tutorial# g++ macro_example.cpp -o a -DSIZE_ARRAY=10 | |
cpp_tutorial# ./a | |
num of elements: 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment