473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

about char pointer

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

Nov 15 '05 #1
13 2086
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.]

--
Chris "electric hedgehog" Dollin
It's called *extreme* programming, not *stupid* programming.
Nov 15 '05 #2
please give some examples

Nov 15 '05 #3

"chellappa" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
please give some examples
Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.
"Chris Dollin" <ke**@hpl.hp.com> wrote in message
news:da**********@malatesta.hpl.hp.com... 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" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... 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
Nov 15 '05 #4

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:YC*******************@newsread2.news.pas.eart hlink.net...

"chellappa" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
please give some examples
Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.
"Chris Dollin" <ke**@hpl.hp.com> wrote in message
news:da**********@malatesta.hpl.hp.com...
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" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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] /* a 'string' */
-Mike

Nov 15 '05 #5
Frank Mikkelsen wrote:
"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:YC*******************@newsread2.news.pas.eart hlink.net...

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.
Nov 15 '05 #6
Frank Mikkelsen wrote:
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.

Nov 15 '05 #7

"Frank Mikkelsen" <50*********@stofanet.dk> wrote in message
news:42***********************@nntp06.dk.telia.net ...

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:YC*******************@newsread2.news.pas.eart hlink.net...

"chellappa" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
please give some examples
Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.
"Chris Dollin" <ke**@hpl.hp.com> wrote in message
news:da**********@malatesta.hpl.hp.com...
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" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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
Nov 15 '05 #8
Mike Wahler wrote:
"Frank Mikkelsen" <50*********@stofanet.dk> wrote in message
news:42***********************@nntp06.dk.telia.net ...

"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:YC*******************@newsread2.news.pas.eart hlink.net...

"chellappa" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
please give some examples

Please preserve context when posting. Thank you.

Please get a textbook. You won't get far without
one.
"Chris Dollin" <ke**@hpl.hp.com> wrote in message
news:da**********@malatesta.hpl.hp.com...
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" <N.*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 15 '05 #9
chellappa wrote:

please give some examples


Of what? of sums? 2+2 = 4; of products? 2 * 3 = 6

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #10
Mike Wahler wrote:
"Frank Mikkelsen" <50*********@stofanet.dk> wrote in message
news:42***********************@nntp06.dk.telia.net ...
"Mike Wahler" <mk******@mkwahler.net> skrev i en meddelelse
news:YC*******************@newsread2.news.pas.ea rthlink.net...
<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, the entire array is initialised, with the elements not
specified by the string literal being initialised to 0.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #11
Robert Gamble wrote:
Mike Wahler wrote:
"Frank Mikkelsen" <50*********@stofanet.dk> wrote
"Mike Wahler" <mk******@mkwahler.net> skrev
"chellappa" <N.*********@gmail.com> 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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #12
On Thu, 07 Jul 2005 01:10:37 GMT, CBFalconer <cb********@yahoo.com>
wrote in comp.lang.c:
Robert Gamble wrote:
Mike Wahler wrote:
"Frank Mikkelsen" <50*********@stofanet.dk> wrote
"Mike Wahler" <mk******@mkwahler.net> skrev
> "chellappa" <N.*********@gmail.com> 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."

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #13
Jack Klein wrote:
CBFalconer <cb********@yahoo.com>
Robert Gamble wrote:
Mike Wahler wrote:
"Frank Mikkelsen" <50*********@stofanet.dk> wrote
> "Mike Wahler" <mk******@mkwahler.net> skrev
>> "chellappa" <N.*********@gmail.com> 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.


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

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: drowned | last post by:
I'm having a problem understanding why the code in this little program I've got is behaving the way it does... if anyone can explain it, I'd be grateful: #include <iostream> using namespace...
11
by: Dmitry D | last post by:
Hi, I'm new to C++ (started learning in the beginning of this summer), and I have the following question (sorry if it sounds stupid): In many code samples and source files, I see NULL expression...
36
by: Bhalchandra Thatte | last post by:
I am allocating a block of memory using malloc. I want to use it to store a "header" structure followed by structs in my application. How to calculate the alignment without making any assumption...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
7
by: Yuri_Юрий | last post by:
I'm confused about the VARIABLE LENGTH ARRAYS. {scanf("%d",&n);float a;} In which compiler can I use it? I tried VC++6.0 SP6,but it's reported error:CONSTANT EXPRESSION! Another question, What...
12
by: Aff | last post by:
Brothers , i am facing a problem which is as follow: class poly { private: char name; int capacity; public: poly(char , int );
14
by: nospam | last post by:
From the book "There is an important difference between these definitions: char amessage="now is the time"; char *pmessage ="now is the time"; snip On the other hand, pmessage is a...
6
by: comp.lang.c++ | last post by:
this is a sample example about this question #include<stdio.h> void chg(char* t) { char *s=t; char p=*t; while(*t++=*++s); *--t=p; } int main()
160
by: raphfrk | last post by:
Is this valid? int a; void *b; b = (void *)a; // b points to a b += 5*sizeof(*a); // b points to a a = 100;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.