Click here to Skip to main content
14,546,341 members

C / C++ / MFC

 
GeneralRe: Passing an array as argument to a function Pin
k505429-Mar-20 4:34
mvek505429-Mar-20 4:34 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan29-Mar-20 5:48
mveRichard MacCutchan29-Mar-20 5:48 
GeneralRe: Passing an array as argument to a function Pin
Stefan_Lang30-Mar-20 23:05
mveStefan_Lang30-Mar-20 23:05 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 23:37
mveRichard MacCutchan30-Mar-20 23:37 
GeneralRe: Passing an array as argument to a function Pin
leon de boer29-Mar-20 15:31
Memberleon de boer29-Mar-20 15:31 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas29-Mar-20 2:19
professionalGreg Utas29-Mar-20 2:19 
GeneralRe: Passing an array as argument to a function Pin
fearless_29-Mar-20 2:58
Memberfearless_29-Mar-20 2:58 
GeneralRe: Passing an array as argument to a function Pin
leon de boer29-Mar-20 4:11
Memberleon de boer29-Mar-20 4:11 
Under C any pointer is already a pointer to an array it's built into the language along with pointer arithmetic ... you need to just learn that.

Literally declare any pointer of anything lets do a float
float* p;
now you can access it as an array
p[0] = 5.0;
p[100] = 10.0;
It will crash because the pointer isn't really to any memory but it makes the point the pointer is already a pointer to an array

There are no exceptions to the rule it doesn't matter if the pointer is to a fundamental type or struct .... so I don't get how you could ever forget that. In the C community the [] use is rare because it's two extra characters to type. It also has implication when declaring variables because it puts that array on the stack not on data memory or constant memory (rodata) if it determines its a constant. So if you get into the habit of using that form you can get some undesirable things happen.

Personally you are learning and I would learn to live without it and just learn them as you will most often see them written.

The topic is well covered in dummies guide to C but you will note the last statement
How to Use Arrays and Functions Together in C Programming - dummies[^]
In vino veritas

GeneralRe: Passing an array as argument to a function Pin
Greg Utas29-Mar-20 5:54
professionalGreg Utas29-Mar-20 5:54 
GeneralRe: Passing an array as argument to a function Pin
fearless_29-Mar-20 6:07
Memberfearless_29-Mar-20 6:07 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan29-Mar-20 4:19
mveRichard MacCutchan29-Mar-20 4:19 
GeneralRe: Passing an array as argument to a function Pin
leon de boer29-Mar-20 4:21
Memberleon de boer29-Mar-20 4:21 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas29-Mar-20 5:53
professionalGreg Utas29-Mar-20 5:53 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan29-Mar-20 6:55
mveRichard MacCutchan29-Mar-20 6:55 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas29-Mar-20 7:07
professionalGreg Utas29-Mar-20 7:07 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan29-Mar-20 7:20
mveRichard MacCutchan29-Mar-20 7:20 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas29-Mar-20 7:50
professionalGreg Utas29-Mar-20 7:50 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan29-Mar-20 21:07
mveRichard MacCutchan29-Mar-20 21:07 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 2:40
professionalGreg Utas30-Mar-20 2:40 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 3:28
mveRichard MacCutchan30-Mar-20 3:28 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 3:35
professionalGreg Utas30-Mar-20 3:35 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 4:04
mveRichard MacCutchan30-Mar-20 4:04 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 4:11
professionalGreg Utas30-Mar-20 4:11 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 4:24
mveRichard MacCutchan30-Mar-20 4:24 
GeneralRe: Passing an array as argument to a function Pin
k505430-Mar-20 4:58
mvek505430-Mar-20 4:58 

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.