Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: string buffer Pin
CPallini10-Dec-07 3:15
mveCPallini10-Dec-07 3:15 
GeneralRe: string buffer Pin
jhwurmbach10-Dec-07 3:51
jhwurmbach10-Dec-07 3:51 
GeneralRe: string buffer Pin
CPallini10-Dec-07 4:04
mveCPallini10-Dec-07 4:04 
GeneralRe: string buffer Pin
jhwurmbach10-Dec-07 4:06
jhwurmbach10-Dec-07 4:06 
GeneralRe: string buffer Pin
George_George10-Dec-07 15:27
George_George10-Dec-07 15:27 
GeneralRe: string buffer Pin
CPallini10-Dec-07 21:46
mveCPallini10-Dec-07 21:46 
GeneralRe: string buffer Pin
George_George10-Dec-07 21:54
George_George10-Dec-07 21:54 
GeneralRe: string buffer Pin
Iain Clarke, Warrior Programmer10-Dec-07 2:04
Iain Clarke, Warrior Programmer10-Dec-07 2:04 
Your examples aren't all that correct. But I think I get the idea of the question.

This will be brief. For a longer version, read a C book. The Kernigan & Richie one taught me loads in a small book.

char array [] = "hello world";


ends up with a constant pointer to chunk of memory holding hello world followed by a zeroed character (NULL).

Same with buf, but it's a constant pointer to a chunk of memory 256 characters long - which could hold anything.

buf is a pointer.

buf [37] is the value in the 37th character in the chunk of memory pointed to by buf.

array[buf] would be the character pointed to by array + an offset of the amount of buf. If buf = 0x12344, this is a big offset.
array(buf) will get the compiler moaning at you, because array is not a function.

Going to array...

array is a pointer to the start of memory holding "hello world".
array[4] is the 4th character in that array. ie 'o', not 'l'.
*array is the character pointed to by array, ie 'h'.
*array and array [0] are equivalent.
array+4 is the pointer to the memory of helloe world, with 4 added to it. So it points to 'o'.
&array[4] is the pointer to the 4th char in the array. same as above.

So...
&array[x] is the same as array+x. The only difference is how similar it looks to the code around it. If the memory is allocated as an array, and that's how you're working on it, &array[0] may be more readable.

If you working on pointers to structures, and your function doesn't know how they're allocated, using array may be more readable.

I hope this helps a little!

Iain.
GeneralRe: string buffer Pin
George_George10-Dec-07 2:18
George_George10-Dec-07 2:18 
GeneralRe: string buffer Pin
Iain Clarke, Warrior Programmer10-Dec-07 2:38
Iain Clarke, Warrior Programmer10-Dec-07 2:38 
GeneralRe: string buffer Pin
George_George10-Dec-07 2:50
George_George10-Dec-07 2:50 
GeneralRe: string buffer Pin
Iain Clarke, Warrior Programmer10-Dec-07 5:26
Iain Clarke, Warrior Programmer10-Dec-07 5:26 
GeneralRe: string buffer Pin
CPallini10-Dec-07 6:06
mveCPallini10-Dec-07 6:06 
GeneralRe: string buffer Pin
George_George10-Dec-07 15:49
George_George10-Dec-07 15:49 
GeneralRe: string buffer Pin
Iain Clarke, Warrior Programmer11-Dec-07 4:44
Iain Clarke, Warrior Programmer11-Dec-07 4:44 
GeneralRe: string buffer Pin
George_George11-Dec-07 21:59
George_George11-Dec-07 21:59 
GeneralRe: string buffer Pin
CPallini10-Dec-07 3:25
mveCPallini10-Dec-07 3:25 
GeneralRe: string buffer Pin
George L. Jackson10-Dec-07 4:43
George L. Jackson10-Dec-07 4:43 
GeneralRe: string buffer Pin
George_George10-Dec-07 15:42
George_George10-Dec-07 15:42 
GeneralRe: string buffer Pin
George L. Jackson10-Dec-07 16:53
George L. Jackson10-Dec-07 16:53 
GeneralRe: string buffer Pin
George_George10-Dec-07 17:50
George_George10-Dec-07 17:50 
QuestionRe: string buffer Pin
David Crow10-Dec-07 4:01
David Crow10-Dec-07 4:01 
GeneralRe: string buffer Pin
CPallini10-Dec-07 6:13
mveCPallini10-Dec-07 6:13 
QuestionRe: string buffer Pin
David Crow10-Dec-07 6:20
David Crow10-Dec-07 6:20 
GeneralRe: string buffer Pin
CPallini10-Dec-07 6:32
mveCPallini10-Dec-07 6:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.