void func(int array[32]) standard confirmed?

B

Barry

void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array << ' ';
}

as the code above shows, I know int array[32] here will decay into int
*, but I still find the number 32 useful for reminding me the array len
Is this code standard confirmed?
 
G

Gianni Mariani

Barry said:
void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array << ' ';
}


You could write it like so:

template <typename T, int N>
void func(T (& array)[N])
{
for (int i = 0; i < N; ++i)
cout << array << ' ';
}

as the code above shows, I know int array[32] here will decay into int
*, but I still find the number 32 useful for reminding me the array len
Is this code standard confirmed?

It is standard.
 
N

Neelesh Bodas

void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array << ' ';


void fun(int (&array)[32])
{
// your code here

}


I wrote the above reply with a thought that you were asking for a
version of 'fun' specifically for an array of size 32. After re-
reading your post, though, I think thats not what you meant.

Anyways.
-N.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top