Re: Doubt about array's name



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



Relevant Pages

  • Re: Data Structure
    ... > char *Parent; ... > int Size; ... the pointers to these global functions. ... functions) working like global functions, and therefore in the source code, ...
    (comp.lang.c)
  • Re: Pointers to Arrays
    ... Nice try to work with pointers ... void segregateXY ... I would like to split it into two 1D arrays, ...
    (comp.lang.c)
  • Re: char vs int
    ... 'a' is a character constant. ... A variable of type char can ... of them instead of int arrays. ... concept of pointers. ...
    (comp.lang.c)
  • Re: Size of a pointer
    ... On many modern platforms, pointers to different types are ... A C char* thus needs to consist of an address, ... on this machine, which would be plausible, then int* would also be 32 ...
    (comp.lang.c.moderated)
  • Re: simple question regarding 5.5 of Ritchie & Kernighan
    ... pointers to char and arrays of char: ... a memory address to hold the value it points to and that memory address ... runtime) multidimensional arrays. ... arrays of pointers to arrays, ...
    (comp.lang.c)