Hello everyone I want to print my define variable in a function. Can anyone explain me how to do this?
Thanks for helping !Code:#define Page 5 #define Test 7 void printDefineVariable() { }
Hello everyone I want to print my define variable in a function. Can anyone explain me how to do this?
Thanks for helping !Code:#define Page 5 #define Test 7 void printDefineVariable() { }
Use printf statement.
Well I googled this problem and I read something that you cant just simple print it. Looks like you can thats confusing me a bit now. One more thing can I also Print the Page too? So my console looks like this : "Page 5" and not only 5
I don't know why you would have that idea but I think it's because you don't know what #define does.
First of all, it's not a variable. It's simply a temporary name. Before the compiler runs, the preprocessor goes around and replaces the defined names with what they were defined as, doing nothing other than simple substitution.
In your case, it replaces Page and Test with 5 and 7 respectively. Nothing more complicated than that. If you know how to print integers, you know how to print those defines you have.
On the other hand, if you want the name of the define, there are some preprocessor tricks you can do, but why bother. Just use the name inside a string.
Last edited by GReaper; 04-26-2017 at 06:30 AM.
Devoted my life to programming...