kevin said:
this is my programm
...
char *p="abcde";
char a[]="abcde";
....
printf("the size of p is:%d\n",sizeof(p));
printf("the size of a is:%d\n",sizeof(a));
....
---------------------------------------------------------
and the output is:
the size of p is:1
the size of a is:6
First, let's write a correct program:
#include <stdio.h> /* a prototype for printf is *REQUIRED* */
int main(void) /* executable code needs a function in which to live */
{
char *p = "abcde";
char a[] = "abcde";
printf("the size of p is %d\n", (int)sizeof p);
printf("the size of a is %d\n", (int)sizeof a);
return 0;
}
If you are getting 1 for p, you have a rather unusual system, in which
bytes are so wide - probably 16 bits or more - that you can fit a
pointer into one. What is more likely is that you typed your question
instead of copying it from your real program.
If your question is simply "why aren't sizeof p and sizeof a the same?",
that's easy. Arrays are not pointers. Pointers are not arrays. Arrays
can be very large indeed, but pointers are generally quite small
(although rarely as small as 1, I must admit). Arrays are cities.
Pointers are signposts. It is possible to imagine a city as small as a
signpost, of course, but one doesn't normally bother.