comp.lang.c
[Top] [All Lists]

Re: Doubt about array's name

Subject: Re: Doubt about array's name
From: Ofloo
Date: Wed, 30 Apr 2008 07:34:01 -0700 PDT
Newsgroups: comp.lang.c

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;
}

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy