chars

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

OK this thing about chars. So a string and a char is two different
things. This is the way I'm understanding things:

char c; is actually a short or int
char *s; s is a pointer to a char and to be used for strings
char foo[5]; is an array used to store so much info.

Do I sound like I'm getting it right now?

Bill
 
D

Default User

Bill said:
OK this thing about chars. So a string and a char is two different
things. This is the way I'm understanding things:

char c; is actually a short or int

No. A char is a char. That is one integer type in C. short is another.
int is another. They are not the same types.
char *s; s is a pointer to a char and to be used for strings

It can be set to point to a string. It doesn't need to. This is
perfectly valid C:

char *s;
char c = 'A';

s = &c;

*s = 'B';

It could set to point to a string literal:

s = "string";

However, that is bad programming practice.

It could point to allocated storage, that might contain a string:

s = malloc(5); /* skipping error check */
strcpy(s, "Hi!");
char foo[5]; is an array used to store so much info.

It is an array of char. It might hold string. It would limited to a
string length of four.
Do I sound like I'm getting it right now?

Reply hazy, check again later.





Brian
 
D

Default User

I was just letting you know where I am getting my information.

Well, that's a decent tutorial. Whether you're getting it or not is
another question (hence, "reply hazy").




Brian
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top