.....it shows declaration not allowed in line7Code:#include<stdio.h> #include<conio.h> #define a 90; void main() { char x=a; int b=10; float c=30.0f; clrscr(); printf("%c %f \n",x,c); getch(); }
.....it shows declaration not allowed in line7Code:#include<stdio.h> #include<conio.h> #define a 90; void main() { char x=a; int b=10; float c=30.0f; clrscr(); printf("%c %f \n",x,c); getch(); }
You have a loose semicolon on line 3. define is not a statement but a preprocessor directive, thus it does not need to be terminated by a semicolon.
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
sorry for that....
......where and how will the values of p and q differ....is there any difference between the meaning of declaration and usage of p and qCode:#include<stdio.h> #include<conio.h> static int p=10; int q=10; void main() { printf("%d %d",p,q); getch(); }
Is this a quiz?
Value will not differ, but usage is p is restricted to file scope by static declaration, whereas q is available for use in other files, unless shadowed there.
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
no no this is a doubt i had......
then how is the declaration of q different if had declared it as
extern int q;
Read up on declaration vs definition in C.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
It didn't work because #define is character substitution not a variable definition.
Your code with this define in it would appear to the compiler as:
Every occurance of the letter a would be substituded with the number 90.Code:void m90in() { ch90r x=90; int b=10; flo90t c=30.0f; clrscr(); printf("%c %f \n",x,c); getch(); }
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
It's the WRONG WAY CORRIGAN rule of #defines (macro's):
Make them clear and use them sparingly. Macro hell is not yet half-full, and it's VERY hot!
I hate macro hell - not a tourist attraction!
A macro for a? You're outta your RAMind.
The real reason it didn't work is because his compiler doesn't support C99 (mixed declarations). The ; at the end of his macro use counted as an actual non-declaration statement. Basically, before C99, unless your compiler had an extension that allowed it, then this was invalid:And thus:Code:int x; /* declaration */ x++; /* non-declaration statement */ int y; /* you can't do this now */Code:char x = 90; /* declaration */ ; /* oops */ float c; /* can't do this now */
Quzah.
Hope is the first step on the road to disappointment.
sorry for that #define blunder...it's solved now....
but i still didn't get the difference b/w the two declarations...regarding there scope,lifetime and usage
.....my doubt is related to C not C++Code:#include<stdio.h> #include<conio.h> static int p=10; int q=10; void main() { printf("%d %d",p,q); getch(); }
So grab your C book, and look up the keyword 'static'. It should explain it. Sounds like you just want another answer without putting out any thought or effort.
Quzah.
Hope is the first step on the road to disappointment.
what i understood is that when a variable is declared as static it doesn't loose it's value even if the scope of the function within which it is declared is finished and a global variable is the one whose value is visible to all the functions......and also what i understand is that if i declare the variables in the way above...their meaning becomes the same......am I right???