Re: ansi c



On 23 Jan, 16:58, yqy...@xxxxxxxxxxx wrote:

thanks, it works, but why i must use "*" pointer?

Because the char type only stores single characters, like 'a' or 'b'.
Pointer types store locations in memory.

If you do
char c = 'a';
you are writing into the variable c the value of the character
'a' (which is just a number).

If you do
char * pc = "cazzo";
you are writing into the variable pc (which is a char pointer) the
*location* of the beginning of the string "cazzo", which is stored in
memory somewhere. You are not storing the whole string "cazzo" in pc,
because no single variable (i.e. not an array) in C can store a whole
string.

(Note single quotes for characters and double quotes for string
literals)
.



Relevant Pages

  • Re: warning: format ?%s? expects type ?char *?, but argument 2 has type ?int?
    ... This reserves storage for one byte of memory - i.e. sufficient to ... If you want to store a string there, ... accept the character pointer *as if* it pointed to an area of memory ... a is a char. ...
    (comp.lang.c)
  • Re: difference between String variable and String class definition
    ... that x and y point to different places in memory and also memory is ... eight characters and pointed to by y. ... store all twelve characters explicitly, ... such an examination might not hold for the next JVM ...
    (comp.lang.java.help)
  • Re: Simple code leads to segfault.. help
    ... non-const char. ... A pointer variable is just like any other variable -- it consumes memory ... The purpose of a double is to store a floating-point number. ... The purpose of a pointer is to store a memory address. ...
    (comp.lang.c)
  • Re: Simple code leads to segfault.. help
    ... They are a non-const pointer to a non-const char. ... A pointer variable is just like any other variable -- it consumes memory and stores data by arranging bits in a particular pattern. ... The purpose of a double is to store a floating-point number. ...
    (comp.lang.c)
  • Re: ansi c
    ... Because the char type only stores single characters, ... Pointer types store locations in memory. ...
    (comp.lang.c)