- Home Page of ProjectGuideline.com ›
- Forums ›
- General Discussion Forum ›
- Programming Competition For Students ›
- difference between global variable and #define.
whats the diff between the following statements
#define YES 1
const int yes=1;
main()
{
}
my quest is both r global to this program and un-changeble. whats the reson to use #define statement?
i too have d doubt.. searched for it… sum informations regarding the difference between cont and #define is there in this.. hope it may help u to some extent..http://www.thescripts.com/forum/thread219595.html
#define YES 1 —->is syablic parameter.
const int yes=1—> Global declartion
Ex:
Take this example to #define GREEN G
#define statement inform to Complier YES as 1
You have different colours. you have to use colour name in your program many place. Each time you have to type each colour name, Its difficult to do that . So we are using #define statement to solve this probelm. Here we are declaring GREEN as G. So if u type G in your program its equal to GREEN.
So as per your question YES as an 1.
cons int yes=1 is static value we can not change the value.
one week have 7 days this is const. So we can declare weekdays as global variable. so
cons int weekdays=7;
I hope your doubt is clear now..
Thanks in advance.