I was just curious to know if it is possible to have a pointer referring to #define constant. If yes, how can I do it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
#definedirective is a directive to the preprocessor, meaning that it is invoked by the preprocessor before anything is even compiled.Therefore, if you type:
#define NUMBER 100And then later you type:
int x = NUMBER;What your compiler actually sees is simply:
int x = 100;It’s basically as if you had opened up your source code in a word processor and did a find/replace to replace each occurrence of “NUMBER” with “100”. So your compiler has no idea about the existence of
NUMBER. Only the pre-compilation preprocessor knows whatNUMBERmeans.So, if you try to take the address of
NUMBER, the compiler will think you are trying to take the address of an integer literal constant, which is not valid.