about char pointer

C

chellappa

hi ,
please explain me , char pointer , char Array, char ,string...
i have some many confussion about this...
please clarify to me..
i need some example about this program
by
chellappa.ns
 
C

Chris Dollin

chellappa said:
please explain me , char pointer , char Array, char ,string...

A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]
 
M

Mike Wahler

chellappa said:
please give some examples

Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.


Chris Dollin said:
chellappa said:
please explain me , char pointer , char Array, char ,string...

A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]

chellappa said:
please give some examples

char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
/ * can represent address of a type 'char' object */

char a[10]; /* 'char array' (a.k.a. 'array of char'). */
/* can store ten type 'char' objects at */
/* contiguous memory locations */

char c; /* a type 'char' object. Can represent any one */
/* of the values of the execution character set */

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
/* a 'string' */


-Mike
 
F

Frank Mikkelsen

Mike Wahler said:
chellappa said:
please give some examples

Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.


Chris Dollin said:
chellappa said:
please explain me , char pointer , char Array, char ,string...

A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]

chellappa said:
please give some examples

char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
/ * can represent address of a type 'char' object */

char a[10]; /* 'char array' (a.k.a. 'array of char'). */
/* can store ten type 'char' objects at */
/* contiguous memory locations */

char c; /* a type 'char' object. Can represent any one */
/* of the values of the execution character set */

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
wrong !! the: char s[10] = "Hello" assign 7 elements, don´t forget the zero
termination of the string at position
s[7]
 
M

Martin Ambuhl

Frank said:
"Mike Wahler" <[email protected]> skrev i en meddelelse
char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements, don´t forget the zero
termination of the string at position
s[7]

Please explain why 5, the strlen("Hello"), + 1 for the terminating '\0'
gives 7.

When you assert that 5+1=7 and label 5+1=6 as "wrong !!", you have an
obligation to expound on your new theory of arithmetic.
 
K

Kevin J. Phillips

Frank said:
char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
wrong !! the: char s[10] = "Hello" assign 7 elements

The prior poster is correct:
s[0] = 'H'
s[1] = 'e'
s[2] = 'l'
s[3] = 'l'
s[4] = 'o'
s[5] = '\0'

That is 6 characters.
don´t forget the zero termination of the string at position s[7]

If you were correct, and "Hello" took seven elements, then s[0]...s[5]
would contain the printable characters and s[6] (the 7th element of the
array), would contain the zero-termination character.
 
M

Mike Wahler

Frank Mikkelsen said:
Mike Wahler said:
chellappa said:
please give some examples

Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.


Chris Dollin said:
chellappa wrote:

please explain me , char pointer , char Array, char ,string...

A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]

chellappa said:
please give some examples

char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
/ * can represent address of a type 'char' object */

char a[10]; /* 'char array' (a.k.a. 'array of char'). */
/* can store ten type 'char' objects at */
/* contiguous memory locations */

char c; /* a type 'char' object. Can represent any one */
/* of the values of the execution character set */

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)

don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

-Mike
 
R

Robert Gamble

Mike said:
Frank Mikkelsen said:
Mike Wahler said:
please give some examples

Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.


chellappa wrote:

please explain me , char pointer , char Array, char ,string...

A decent book on C will explain all this, and be faster than
drip-feeding via Usenet. But:

A `char pointer` is a pointer that points to characters.
A `char array` is an array whose elements are characters.
A `char` is a value which is/represents a character.
A `string` is a sequence of characters terminated by a
null (== 0) character.

[A `sequence of characters` is a contiguous slice out of an
array or mallocated store.]

please give some examples

char *p; /* 'char pointer' (a.k.a. 'Pointer to char'). */
/ * can represent address of a type 'char' object */

char a[10]; /* 'char array' (a.k.a. 'array of char'). */
/* can store ten type 'char' objects at */
/* contiguous memory locations */

char c; /* a type 'char' object. Can represent any one */
/* of the values of the execution character set */

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */
wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)

don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

Actually, s[6] through s[9] *have* been initialized to '\0'.

Robert Gamble
 
F

Flash Gordon

Mike said:
"Mike Wahler" <[email protected]> skrev i en meddelelse
news:[email protected]...
char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)
don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

Actually, the entire array is initialised, with the elements not
specified by the string literal being initialised to 0.
 
C

CBFalconer

Robert said:
.... snip ...
char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)
don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

Actually, s[6] through s[9] *have* been initialized to '\0'.

I doubt it. To argue it you have to first present a complete
compilable source.
 
J

Jack Klein

Robert said:
Mike said:
"Mike Wahler" <[email protected]> skrev
"chellappa" <[email protected]> wrote
... snip ...
char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)

don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

Actually, s[6] through s[9] *have* been initialized to '\0'.

I doubt it. To argue it you have to first present a complete
compilable source.

No, you don't, because neither the linkage nor the storage duration of
the object in question have any effect on the truth of the statement.
Any place in a C file where the definition:

char s[10] = "Hello";

....is legal and valid, the effect of having any initializer present
guarantees that all 10 characters are initialized. And it
specifically guarantees that any for which there are insufficient
initializers are default initialized with 0.

6.7.8 P 21:
"If there are fewer initializers in a brace-enclosed list than there
are elements or members of an aggregate, or fewer characters in a
string literal used to initialize an array of known size than there
are elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration."
 
C

CBFalconer

Jack said:
CBFalconer said:
Robert said:
Mike Wahler wrote:
"Mike Wahler" <[email protected]> skrev
... snip ...

char s[10] = "Hello" ; /* 'char array' (a.k.a. 'array of char'). */
/* The first six elements of the array */
/* (s[0] through s[5] inclusive) comprise */

wrong !! the: char s[10] = "Hello" assign 7 elements,

Really? Please explain.

(BTW that definition dos not 'assign' anything, it
*initializes* the first six characters of the array.
Initialization and assigment are not the same thing.)

don´t forget the zero termination of the string at position
s[7]

I did not forget about the terminator, but it's location
is s[5]. None of s[6] through s[9] have been initialized or
assigned a valid value.

Actually, s[6] through s[9] *have* been initialized to '\0'.

I doubt it. To argue it you have to first present a complete
compilable source.

No, you don't, because neither the linkage nor the storage duration of
the object in question have any effect on the truth of the statement.
Any place in a C file where the definition:

char s[10] = "Hello";

...is legal and valid, the effect of having any initializer present
guarantees that all 10 characters are initialized. And it
specifically guarantees that any for which there are insufficient
initializers are default initialized with 0.

Consider my objection withdrawn. Thanks for the correction. All I
can say is that I erred in the safe direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top