sa*****@yahoo.co.in writes:
I have the following two cases,
typedef char* cptr;
const cptr ch;
//here ch is a pointer to a character and the pointer is a constant
here...
where as
#define CPTR char*
const CPTR ch;
//here ch is a pointer to character and the character is a constant
here...
What is the reason behind this???
A typedef creates an alias for a type. Macro expansion works on text
(tokens, actually) with no regard for what those tokens might mean in
context.
In your second example, "CPTR" expands to "char*", so the declaration
is:
const char* ch;
Consider also the following example:
#include <stdio.h>
#define SIX 1+5
#define NINE 8+1
int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.