void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array[i] << ' ';
}
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? 3 2029
Barry wrote:
void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array[i] << ' ';
}
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[i] << ' ';
}
>
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.
On Jul 31, 1:27 pm, Barry <dh...@126.comwrote:
void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array[i] << ' ';
}
void fun(int (&array)[32])
{
// your code here
}
-N
On Jul 31, 3:14 pm, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 31, 1:27 pm, Barry <dh...@126.comwrote:
void func(int array[32]) {
for (int i = 0; i < 32; ++i)
cout << array[i] << ' ';
}
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.
>
-N
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anupam |
last post by:
Hi,
This was asked on our school newsgroup by a friend of mine.
He gave the following code and said that it did not print out
the elements of the array. He asked for an explanation for this...
|
by: David Mathog |
last post by:
If this:
int i,sum;
int *array;
for(sum=0, i=0; i<len; i++){
sum += array;
}
is converted to this (never mind why for the moment):
|
by: Vinko Vrsalovic |
last post by:
Hello,
I read a couple of posts ago that these are not equivalent, and that
the former means 'no arguments specified' and that calling for
instance func(3,"THREE",&myint) is legal.
What's the...
|
by: codergem |
last post by:
One common answer is that all compilers keep the size of integer the
same as the size of the register on a particular architecture. Thus, to
know whether the machine is 32 bit or 64 bit, just see...
|
by: Bill Pursell |
last post by:
The following code generates a compiler warning
when compiled with gcc -pedantic:
typedef (*FUNC)(int);
FUNC f;
void *
get_f(void)
{
return &f;
|
by: Lighter |
last post by:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-
pointer standard conversionsare not applied to the left expressions"?
In 5.18 Comma operator of the C++ standard, there is a...
|
by: =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= |
last post by:
Coming originally from C++, I used to do the likes of the following,
using a pointer in a conditional:
void Func(int *p)
{
if (p)
{
*p++ = 7;
*p++ = 8;
|
by: junky_fellow |
last post by:
Guys,
Consider a function
func(void **var)
{
/* In function I need to typecast the variable var as (int **)
I mean to say, I need to access var as (int **)
}
|
by: Peerless |
last post by:
Hi,
For some reason the below code doesnt produce results as i expect.
#include<stdio.h>
int main()
{
int hi=0xff;
int low=0xee;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |