Qbasicnews.com

Full Version: Help with C syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
http://www.google.com/search?hl=en&ie=UT...%23declare

I can't figure out how to use #declare the same way you use CONST. I found this page:

http://www.povray.org/documentation/view/146/

But I'm not sure if it's even C!

Please help.
Use #define.

Code:
#define YOURCONST 1234
printf("%d", YOURCONST);
Plasma's solution will work but as an alternative you can use the const keyword:

Code:
const int x = 5;

printf("Constant x = %d\n", x);

The #define method given by Plasma has the preprocessor replace all occurances of YOURCONST with the string of text (its not actually a value as such) 1234 before compiling. This is fine for most solutions, except when you want some finer control, for example:

Code:
#define YOURCONST 1234
const int x = 5;

/* Okay, because x is a variable */
printf("Address of x = %d\n", &x);

/* Not okay, because YOURCONST is just a number */
printf("Address of YOURCONST = %d\n", &YOURCONST);
Thanks guys.