Differences between char array[SIZE] and char *array 
Author Message
 Differences between char array[SIZE] and char *array

I've seen some situations where using one will work and the other will
result in strange behavior, what really is the difference between
these two declarations besides char *array has to be allocated memory?


Tue, 25 May 2004 21:53:55 GMT  
 Differences between char array[SIZE] and char *array

Quote:

> I've seen some situations where using one will work and the other will
> result in strange behavior, what really is the difference between
> these two declarations besides char *array has to be allocated memory?

James...

char *array is a pointer to one or more chars (somewhere?)

char array[SIZE] is an actual sequence of SIZE chars in memory.

HTH
--
Morris Dovey
West Des Moines, Iowa USA



Tue, 25 May 2004 21:10:48 GMT  
 Differences between char array[SIZE] and char *array

Quote:
> I've seen some situations where using one will work and the other will
> result in strange behavior, what really is the difference between
> these two declarations besides char *array has to be allocated memory?

Other than the one you're already covered, there are two other
differences:
(1) A pointer can be reassigned to point to anything it wishes. An
array stays put pointing at the same space.
(2) The sizeof operator returns SIZE when applied to char array[SIZE],
but the size of a char pointer when applied to char *array.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"We sorcerers don't like to eat our words, so to say."
   - Sparrowhawk



Tue, 25 May 2004 22:29:49 GMT  
 Differences between char array[SIZE] and char *array

Quote:
>I've seen some situations where using one will work and the other will
>result in strange behavior, what really is the difference between
>these two declarations besides char *array has to be allocated memory?

The FAQ has a whole section dedicated to the issue.  Why didn't you read
it before posting?

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Tue, 25 May 2004 23:55:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Converting char array of literals chars to escape chars

2. A char pointer (char *) vs. char array question

3. char array (array of array...) question

4. Char* array to Unsigned Char*

5. char pointer to 2D char array

6. char* to char array[] ?

7. char arrays versus char strings.

8. Passing a char array[n] to a function expecting a char*

9. arrays and pointers, char * vs. char [], distinction

10. char arrays size , seg fault?

11. The sizes of char arrays

12. returning variable size char arrays

 

 
Powered by phpBB® Forum Software