|
|
On 30 apr, 15:34, nembo kid <u...@xxxxxxxxxxxxx> wrote:
> In the following function, s shouldn't be a pointer costant (array's name)?
>
> So why it is legal its increment? Thanks in advance.
>
> /* Code starts here */
> void chartobyte (char *s) {
>
> while (s!=0) {
> printf ("%d", *s);
> s++;}
>
> /* Code ends here */
From what i understood from arrays is that array[0] == *array and
array[1] == array++; *array .. and so forth if the predefined size of
the pointer is 4bytes array++ will go to the next 4bytes in memory ..
basicly pointers are arrays and arrays are pointers, .. the other
thing should work also the other way arround, ..
#include <stdio.h>
#include <string.h>
int main() {
int i;
char *p_str = "mystring";
printf ("%s\n", p_str);
for (i = 0;i < strlen(p_str); i++)
printf ("%c", p_str[i]);
printf ("\n");
return 0;
}
|
|