You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

588 lines
39 KiB

<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Arduino FAQ - Passing arrays to functions</title>
<base href="http://arduino.land/FAQ/" />
<meta name="description" content="A big topic for beginners is how to write a function that can ...">
<meta name="keywords" content=" function, reference,Arduino FAQ, pointer, arduino,cpp, c++, array, pass">
<meta name="author" content="Christopher Andrews">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="phpMyFAQ 2.8.15">
<meta name="robots" content="INDEX, FOLLOW">
<meta name="revisit-after" content="7 days">
<!-- Share on Facebook -->
<meta property="og:title" content="Arduino FAQ - Passing arrays to functions" />
<meta property="og:description" content="A big topic for beginners is how to write a function that can ..." />
<meta property="og:image" content="" />
<link rel="stylesheet" href="/../CSS/faq.main.scss">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="shortcut icon" href="http://arduino.land/FAQ/assets/template/arduino-land-2/favicon.ico">
<link rel="apple-touch-icon" href="http://arduino.land/FAQ/assets/template/arduino-land-2/apple-touch-icon.png">
<link rel="canonical" href="http://arduino.land/FAQ/content/6/32/en/passing-arrays-to-functions.html">
<script src="http://arduino.land/FAQ/assets/js/libs/modernizr.min.js"></script>
<script src="http://arduino.land/FAQ/assets/js/phpmyfaq.min.js"></script>
<link rel="alternate" title="News RSS Feed" type="application/rss+xml" href="http://arduino.land/FAQ/feed/news/rss.php">
<link rel="alternate" title="TopTen RSS Feed" type="application/rss+xml" href="http://arduino.land/FAQ/feed/topten/rss.php">
<link rel="alternate" title="Latest FAQ Records RSS Feed" type="application/rss+xml" href="http://arduino.land/FAQ/feed/latest/rss.php">
<link rel="alternate" title="Open Questions RSS Feed" type="application/rss+xml" href="http://arduino.land/FAQ/feed/openquestions/rss.php">
<link rel="search" type="application/opensearchdescription+xml" title="Arduino FAQ - Passing arrays to functions" href="http://arduino.land/FAQ/opensearch.html">
</head>
<body dir="ltr">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48223018-1', 'arduino.land');
ga('require', 'linkid', 'linkid.js');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
<!--[if lt IE 8 ]>
<div class="internet-explorer-error">
Do you know that your Internet Explorer is out of date?<br/>
Please use Internet Explorer 8+, Mozilla Firefox 4+, Google Chrome, Apple Safari 5+ or Opera 11+
</div>
<![endif]-->
<div class="navbar navbar-fixed-top hidden-print">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" title="Arduino FAQ" href="http://arduino.land/FAQ">Arduino FAQ</a>
<nav class="nav-collapse">
<ul class="nav">
<li class=""><a href="http://arduino.land/FAQ/instantresponse.html">Instant Response</a></li>
<li class=""><a href="http://arduino.land/FAQ/addcontent.html">Add new FAQ</a></li>
<li class=""><a href="http://arduino.land/FAQ/ask.html">Add question</a></li>
<li class=""><a href="http://arduino.land/FAQ/open.html">Open questions</a></li>
</ul>
<ul class="nav pull-right">
<li class=""><a href="?action=register">Sign up</a></li>
<li class="divider-vertical"></li>
<li class=""><a href="?action=login">Login</a></li>
</ul>
</nav>
</div>
</div>
</div>
<section id="content" class="container-fluid">
<div class="row-fluid">
<div class="span3 hidden-print" id="leftContent">
<div class="well categories">
<ul class="nav nav-list">
<li class="home"><a href="http://arduino.land/FAQ/index.html">FAQ Home</a></li>
<li class="test-lst"><a href="http://arduino.land/FAQ/showcat.html">All categories</a></li>
<li class="divider-horizontal"></li>
<li><a id="category_1" title="This category holds commonly asked questions on the Arduino forum." href="/FAQ/category/1/using-arduino.html">Using Arduino <img src="assets/img/more.gif" width="11" height="11" alt="Using Arduino" style="border: none; vertical-align: middle;" /></a></li>
<li><a id="category_0" href="/FAQ/showcat.html">Programming Arduino</a>
<ul class="nav nav-list">
<li><a id="category_4" title="A few closely related articles about memory, allocation, and general usage" href="/FAQ/category/4/memory-%26-storage.html">Memory & storage</a></li>
<li class="active"><a class="active" id="category_6" title="A collection of answers specifically involving arrays." href="/FAQ/category/6/arrays.html">Arrays</a></li>
<li><a id="category_8" title="A set of answers describing some common errors encountered in C++ and Arduino" href="/FAQ/category/8/errors.html">Errors</a></li>
<li><a id="category_9" title="Topics centered around utilizing the AVR flash memory." href="/FAQ/category/9/progmem.html">PROGMEM</a></li>
</ul>
</li>
<li><a id="category_3" title="This section contains FAQ articles that may be unrelated to Arduino & C++, but support FAQ&#39;s in other categories." href="/FAQ/category/3/miscellaneous.html">Miscellaneous</a></li>
</ul>
<div class="users-online">
<small>1 user online | 1 Guest and 0 Registered</small>
</div>
</div>
<div class="well adbox">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ad_sm_sq" data-ad-client="ca-pub-2585293717740875" data-ad-slot="4911891944"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
</div>
<div class="span6" id="mainContent">
<div id="breadcrumbs" class="hidden-print">
<ul class="breadcrumb"><li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/FAQ/category/2/programming-arduino.html" itemprop="url" rel="index"><span itemprop="title">Programming Arduino</span></a></li><li class="divider"> &raquo; </li><li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a title="A collection of answers specifically involving arrays." href="/FAQ/category/6/arrays.html" itemprop="url"><span itemprop="title">Arrays</span></a></li></ul>
</div>
<header>
<div class="pull-right hidden-print" id="solution_id">
<a class="label label-info" href="/FAQ/index.php?solution_id=1031">
ID #1031
</a>
</div>
<h2>Passing arrays to functions</h2>
</header>
<hr>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- FAQ-banner-top -->
<ins class="adsbygoogle"
style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-2585293717740875"
data-ad-slot="6042234340"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr>
<article class="answer">
<p>A big topic for beginners is how to write a function that can be passed an array. A very common way of achieving this is done using pointers. This method can be seen all through the C core in functions like <code>memcpy()</code>. Another way, which is the more natural choice for C++, but not as popular with beginners and C programmers is to pass the variable as an actual array. Both methods have their advantages, however each has their drawbacks. How you need to use the array in your own code should determine which is best.</p>
<ul>
<li><a href="/FAQ/content/6/32/en/passing-arrays-to-functions.html#pass-an-array-using-pointer"><strong>Pass an array using a pointer</strong></a>
<ul>
<li>
<p><a title="Goto section." href="/FAQ/content/6/32/en/passing-arrays-to-functions.html#pass-multi-by-pointer"><strong>Pass a multidimensional array using pointer</strong></a></p>
</li>
</ul>
</li>
<li><strong><strong><a href="/FAQ/content/6/32/en/passing-arrays-to-functions.html#pass-an-array">Pass an array using array types</a> (single &amp; multidimensional)</strong></strong></li>
</ul>
<hr />
<p> </p>
<h4><a name="pass-an-array-using-pointer"></a>Pass an array using a pointer</h4>
<p>An arrays name in code, without subscript operators <code>[]</code>, is implicitly convertible to a pointer of its first element. An example of this is shown below. The pointer to <code>arr[0]</code> is assigned to the variable <code>ptr</code>. Contrary to popular belief, this is not a pointer to the array, and the array has implicitly been cast to a pointer, which is commonly referred to as <em>decayed pointer</em>, as it has been stripped of the information an array type provides. The example also shows how you can explicitly get the pointer of any array element.</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">char arr[] = { 1, 2, 3, 4, 5 };
char *ptr = arr;
//Or the equivalent ( change index to start mid-array ):
char *ptr2 = &amp;arr[0];</pre>
<p>Once we have a pointer to an element, you can also use pointer arithmetic to navigate the array. When passing an array to a function using pointers, you can convert it to a pointer using the two methods explained above. The next example shows this basic principle in the function <code>setup()</code>:</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">#define MAX_LEN 5
char arr[ MAX_LEN ] = { 1, 2, 3, 4, 5 };
void Func( char *ptr ){
for( int idx = MAX_LEN - 1 ; idx &gt;= 0 ; --idx ){
Serial.println( ptr[ idx ], HEX );
}
}
void setup(){
Serial.begin( 9600 );
Func( arr );
}
void loop() {}</pre>
<p>The above setup works, however the function is limited in the fact it can not be reused easily. To make the code more generic and increase its reuseability, we can remove the hard coded length and pass it through the function also.</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">char arr[] = { 1, 2, 3, 4, 5 };
void Func( char *ptr, int length ){
while( length ){
Serial.println( ptr[ --length ], HEX );
}
}
void setup(){
Serial.begin( 9600 );
Func( arr, 5 );
Serial.println( "----------------" );
Func( &amp;arr[2], 3 );
}
void loop() {}</pre>
<p>Now the function allows arrays of any length you want. This method is almost always required to deal with an array of unknown size as the typical methods of <a title="Goto FAQ article" href="content/6/29/en/how-to-get-the-size-of-an-array.html" target="_blank">retrieving the length of an array</a> do not work with the pointer.</p>
<h5><a name="pass-multi-by-pointer"></a>Pass a multidimensional array using pointer</h5>
<p>The above example is a common and accepted way of dealing with array data. However this method is not as straight forward when using multidimensional arrays, for example, two dimensional array types do not convert to a 2D pointer (something like <code>char **ptr</code>). To pass a multidimensional array you must know the value of all dimensions except the first, so things become a little more restrictive.</p>
<p>This short example shows how a multidimensional array can be passed. The functions <code>Func()</code> &amp; <code>Func2()</code> are two different styles used to pass a multidimensional array, and just like the examples above you can add in extra parameters to tell the function the length of each dimension:</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">void Func( char array[][3] ){
return;
}
void Func2( char (*array)[3] ){
return;
}
void setup() {
char arr[][3] = {
{ 0, 1, 2 },
{ 3, 4, 5 },
{ 6, 7, 8 }
};
Func( arr );
Func2( arr );
}
void loop() {}</pre>
<p>As you can see, with each extra dimension, the functions accepting the pointer become less and less generic and more specific to a particular array. This is where templates could be used to gain a more generic interface<span>. However templates can provide many more capabilities and these are explained in the next section below.</span></p>
<hr />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- FAQ-banner-top -->
<ins class="adsbygoogle"
style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-2585293717740875"
data-ad-slot="6042234340"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr/>
<h4><a name="pass-an-array"></a>Pass an array using array types</h4>
<p>Rather than having an array decay to a pointer every time you need to use it, you can utilize a reference object. Arrays themselves are types, which means we can create pointers and references to them just like any other type. The syntax becomes a little obscure due to the nature of the array declaration, however it allows for a different style of programming to the pointer methods in the section above.</p>
<p>For example, we cannot simply add an <code>&amp;</code> symbol to mark the array as a reference like: <code>char &amp;array[5]</code> as this declares an array of references, which is illegal, and not what we want (a reference to an array). The <code>&amp;</code> needs to be inside brackets to show its part of the array variable, and not the array data type: <code>char (&amp;array)[5]</code>.</p>
<p>In the following example, a function taking a reference to an array can replace the first two examples in the pointer method above:</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">void Func( char (&amp;array)[5] ){
for( int idx = 0 ; idx &lt; sizeof( array ) ; ++idx ){
Serial.println( array[ idx ], HEX );
}
}
void setup() {
Serial.begin( 9600 );
char arr[] = { 1,2,3,4,5 };
Func( arr );
}
void loop(){}</pre>
<p> If you haven&#39;t already noticed, the function does not need the length to be passed in as <code>sizeof</code> will work correctly with a reference. The same function can be rewritten using an actual <em>pointer to array</em>, the only difference is the need to <em>dereference</em> the pointer back to an array before using it:</p>
<pre class="brush: bash;collapse: true;fontsize: 100; first-line: 1; ">void Func( char (*array)[5] ){
for( int idx = 0 ; idx &lt; sizeof( *array ) ; ++idx ){
Serial.println( (*array)[ idx ], HEX );
}
}
//...
char arr[] = { 1,2,3,4,5 };
Func( &amp;arr ); //Pass the &#39;address of&#39; the array.</pre>
<p>These examples, while useful, are still bound to an array of a certain length and are not quite as flexible as one may need. To write a function which will accept any size array, we can start to adopt some template features. The first change we can make is to let the compiler deduce the length of the array, so we can write one piece of code for any sized array (single dimension).</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">template&lt; size_t N &gt;
void Func( char (&amp;array)[N] ){
for( int idx = 0 ; idx &lt; N ; ++idx ){
Serial.println( array[ idx ], HEX );
}
}</pre>
<p>The template parameter <code>N</code> will be replaced with a usable value when called with an array. And in the declaration we can replace the hard coded value with <code>N</code>. As this value is accessible as a constant within the function, it also eliminates the need for sizeof.</p>
<p>The next modification we can add is to allow arrays of any data type to use the function. This requires an additional template parameter, which we can use to replace the array type <code>char</code>:</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">template&lt; typename T, size_t N &gt;
void Func( T (&amp;array)[N] ){
//code here
}</pre>
<p>To write a version of this function for multidimensional arrays we can simply add a new template parameter for each dimension:</p>
<pre class="brush: cpp;collapse: true; fontsize: 100; first-line: 1; ">template&lt; typename T, size_t N, size_t X &gt;
void Func( T (&amp;array)[N][X] ){
//Code here
}<br />
template&lt; typename T, size_t N, size_t X, size_t Y &gt;
void Func( T (&amp;array)[N][X][Y] ){
//Code here
}</pre>
<p>The benefit is each dimension is known and can be easily iterated. Heavy use of template style functions with different sized arrays could lead to code bloat, so these functions could be used as wrappers for pointer style functions, or to map multidimensional arrays onto functions accepting single dimension, which can be optimized very well by the compiler.</p>
Tags: <a title="array" href="/FAQ/tags/35/array.html">array</a>, <a title="function" href="/FAQ/tags/130/function.html">function</a>, <a title="pointer" href="/FAQ/tags/131/pointer.html">pointer</a>, <a title="reference" href="/FAQ/tags/2/reference.html">reference</a>
<aside id="faqAccordion" class="accordion related-faqs hidden-print">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" href="#collapseRelatedFaqs" data-parent="#faqAccordion" data-toggle="collapse">
Related entries
</a>
</div>
<div id="collapseRelatedFaqs" class="accordion-body collapse">
<div class="accordion-inner"><ul><li><a title="What is the Arduino language" href="/FAQ/content/1/1/en/what-is-the-arduino-language.html">What is the Arduino language</a></li><li><a title="Can I use int main() with Arduino" href="/FAQ/content/2/2/en/can-i-use-int-main-with-arduino.html">Can I use int main() with Arduino</a></li><li><a title="What does the IDE change in my sketch" href="/FAQ/content/1/3/en/what-does-the-ide-change-in-my-sketch.html">What does the IDE change in my sketch</a></li><li><a title="I can&#39;t upload a sketch with !!! in a string" href="/FAQ/content/1/6/en/i-can_t-upload-a-sketch-with-in-a-string.html">I can&#39;t upload a sketch with !!! in a string</a></li><li><a title="What is the maximum number of elements an array can have" href="/FAQ/content/6/7/en/what-is-the-maximum-number-of-elements-an-array-can-have.html">What is the maximum number of elements an array can have</a></li></ul></div>
</div>
</div>
</aside>
</article>
<script>
$(function(){
$('abbr[rel="tooltip"]').tooltip();
});
</script>
<ul id="tab" class="nav nav-tabs hidden-print">
<li class="active"><a href="#authorInfo" data-toggle="tab">About this FAQ</a></li>
<li><a href="#votingForm" data-toggle="tab">Rate this FAQ</a></li>
<li></li>
</ul>
<div class="tab-content faq-information">
<div class="tab-pane active" id="authorInfo">
<dl class="dl-horizontal">
<dt>Last update: </dt><dd>2014-10-26 06:02</dd>
<dt>Author:</dt><dd>Christopher Andrews</dd>
<dt>Revision:</dt><dd>1.0</dd>
</dl>
</div>
<div class="tab-pane hidden-print" id="votingForm">
<form action="#" method="post" class="form-inline" accept-charset="utf-8">
<input type="hidden" name="artikel" value="32">
<div id="votings"></div>
<div class="star-rating">
<span data-stars="5"></span>
<span data-stars="4"></span>
<span data-stars="3"></span>
<span data-stars="2"></span>
<span data-stars="1"></span>
</div>
<div class="pull-right">
<strong>Average rating:</strong><span id="rating"> 4.5 (8 Votes)</span>
</div>
</form>
</div>
<div class="tab-pane hidden-print" id="switchAvailableLanguage">
</div>
<div class="tab-pane hidden-print" id="addTranslation">
<form action="/FAQ/index.php?action=translate&amp;cat=6&amp;id=32&amp;srclang=en" method="post" class="form-inline" accept-charset="utf-8">
<select class="language" name="translation" id="translation" size="1">
<option value="ar">Arabic</option>
<option value="eu">Basque</option>
<option value="bn">Bengali</option>
<option value="bs">Bosnian</option>
<option value="pt-br">Brazilian Portuguese</option>
<option value="zh">Chinese (Simplified)</option>
<option value="tw">Chinese (Traditional)</option>
<option value="cs">Czech</option>
<option value="da">Danish</option>
<option value="nl">Dutch</option>
<option value="fi">Finnish</option>
<option value="fr">French</option>
<option value="fr-ca">French (Canada)</option>
<option value="de">German</option>
<option value="el">Greek</option>
<option value="he">Hebrew</option>
<option value="hi">Hindi</option>
<option value="hu">Hungarian</option>
<option value="id">Indonesian</option>
<option value="it">Italian</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="lv">Latvian</option>
<option value="lt">Lithuanian</option>
<option value="ms">Malay</option>
<option value="nb">Norwegian Bokm&aring;l</option>
<option value="fa">Persian</option>
<option value="pl">Polish</option>
<option value="pt">Portuguese</option>
<option value="ro">Romanian</option>
<option value="ru">Russian</option>
<option value="sr">Serbian</option>
<option value="sk">Slovak</option>
<option value="sl">Slovenian</option>
<option value="es">Spanish</option>
<option value="sv">Swedish</option>
<option value="th">Thai</option>
<option value="tr">Turkish</option>
<option value="uk">Ukrainian</option>
<option value="vi">Vietnamese</option>
<option value="cy">Welsh</option>
</select>
<button class="btn btn-primary" type="submit" name="submit">
Start translation...
</button>
</form>
</div>
</div>
<p class="hidden-print">You can <a href="javascript:void(0);" onclick="javascript:$('#commentForm').show();">comment this FAQ</a></p>
<a id="comment"></a>
<div id="commentForm" class="hide">
<form id="formValues" action="#" method="post" class="form-horizontal" accept-charset="utf-8">
<input type="hidden" name="id" id="id" value="32">
<input type="hidden" name="lang" id="lang" value="en">
<input type="hidden" name="type" id="type" value="faq">
<div class="control-group">
<label class="control-label" for="user">Your name:</label>
<div class="controls">
<input type="text" id="user" name="user" value="" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="mail">Email</label>
<div class="controls">
<input type="email" id="mail" name="mail" value="" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="comment_text">Your comment:</label>
<div class="controls">
<textarea id="comment_text" name="comment_text" required></textarea>
</div>
</div>
<div class="control-group"> <label class="control-label"></label> <div class="controls"><img id="captchaImage" src="/FAQ/index.php?action=writecomment&amp;gen=img&amp;ck=1549085170" height="40" width="165" alt="Chuck Norris has counted to infinity. Twice." title="click to refresh"> </div></div><div class="control-group"><label class="control-label">Please enter the captcha code</label> <div class="controls"> <div class="input-append"><input type="text" name="captcha" id="captcha" size="6" required><a class="btn" id="captcha-button" data-action="writecomment"><i class="icon-refresh"></i></a> </div> </div></div>
<div class="form-actions">
<button class="btn btn-primary" id="submitcomment" type="submit">
submit
</button>
</div>
</form>
</div>
<div id="loader"></div>
<div id="comments">
<p class="comment"><img class="commment-bubbles" src="assets/img/bubbles.gif" /><strong>Comment of <a href="mailto:no_AT_email_DOT_com">per</a>:</strong><br />Thanks so much for this FAQ it was very useful to me. A small typo, in <span class="comment-dots-32">... </span><a onclick="showLongComment(32)" class="comment-show-more-32 pointer">show more</a><span class="comment-more-32 hide">the last code sample there is a &#60;br&#62; that I don&#39;t think was intended. </span><br /><small>Added at: 2015-07-08 13:56</small></p>
</div>
<script>
$(function() {
$("div.star-rating > span").on("click", function(e) {
var numStars = $(e.target).data("stars");
saveVoting("faq", 32, numStars, "en");
});
});
$('form#formValues').on('submit', function (e) {
e.preventDefault();
saveFormValues('savecomment', 'comment');
return false;
});
</script>
<style scoped>
@import "http://arduino.land/FAQ/assets/js/syntaxhighlighter/styles/shCore.css";
@import "http://arduino.land/FAQ/assets/js/syntaxhighlighter/styles/shThemeDefault.css";
</style>
<script src="http://arduino.land/FAQ/assets/js/syntaxhighlighter/scripts/shCore.js"></script>
<script src="http://arduino.land/FAQ/assets/js/syntaxhighlighter/scripts/shAutoloader.js"></script>
<script>
SyntaxHighlighter.autoloader(
'js jscript javascript assets/js/syntaxhighlighter/scripts/shBrushJScript.js',
'applescript assets/js/syntaxhighlighter/scripts/shBrushAppleScript.js',
'xml xhtml xslt html assets/js/syntaxhighlighter/scripts/shBrushXml.js',
'bash shell assets/js/syntaxhighlighter/scripts/shBrushBash.js',
'php assets/js/syntaxhighlighter/scripts/shBrushPhp.js',
'sql assets/js/syntaxhighlighter/scripts/shBrushSql.js',
'cpp assets/js/syntaxhighlighter/scripts/shBrushCpp.js',
'plain assets/js/syntaxhighlighter/scripts/shBrushPlain.js'
);
//This is a temporary fix and can be removed once a proper solution is found.
//Removes unrendered glossary entries injected into source code.
$( 'pre' ).find( 'abbr,mark' ).replaceWith( function (){ return $( this ).text(); } );
SyntaxHighlighter.all();
</script>
</div>
<div class="span3 hidden-print" id="rightContent">
<section class="well">
<div id="social">
<a href="https://www.facebook.com/sharer.php?u=http%3A%2F%2Farduino.land%2FFAQindex.php%3Faction%3Dartikel%26cat%3D6%26id%3D32%26artlang%3Den" target="_blank" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/facebook.png" alt="Share on Facebook" title="Share on Facebook" width="32" height="32" >
</a>
<a href="https://twitter.com/share?url=http%3A%2F%2Farduino.land%2FFAQindex.php%3Faction%3Dartikel%26cat%3D6%26id%3D32%26artlang%3Den&text=Passing+arrays+to+functions+%7C+http%3A%2F%2Farduino.land%2FFAQindex.php%3Faction%3Dartikel%26cat%3D6%26id%3D32%26artlang%3Den" target="_blank" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/twitter.png" alt="Share on Twitter" title="Share on Twitter" width="32" height="32" >
</a>
<a href="http://digg.com/submit?phase=2&url=http%3A%2F%2Farduino.land%2FFAQindex.php%3Faction%3Dartikel%26cat%3D6%26id%3D32%26artlang%3Den%26title%3DPassing%2Barrays%2Bto%2Bfunctions" target="_blank" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/digg.png" alt="Digg it!" title="Digg it!" width="32" height="32" >
</a>
<a href="http://arduino.land/FAQ?action=send2friend&cat=6&id=32&artlang=en" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/email.png" alt="Send FAQ to a friend" title="Send FAQ to a friend" width="32" height="32" >
</a>
<a target="_blank" href="/FAQ/pdf.php?cat=6&id=32&artlang=en" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/pdf.png" alt="PDF version" title="PDF version" width="32" height="32" >
</a>
<a href="javascript:window.print();" rel="nofollow">
<img src="http://arduino.land/FAQ/assets/img/print.png" alt="Print this record" title="Print this record" width="32" height="32" >
</a>
</div>
<div id="facebookLikeButton">
</div>
</section>
<section class="well">
<header>
<h3>Records in this category</h3>
</header>
<div id="allCategoryArticles-content">
<ul class="phpmyfaq_ul"><li><a title="What is the maximum number of elements an array can have" href="/FAQ/content/6/7/en/what-is-the-maximum-number-of-elements-an-array-can-have.html">What is the maximum number of elements an array can have</a></li><li><a title="How to get the size of an array" href="/FAQ/content/6/29/en/how-to-get-the-size-of-an-array.html">How to get the size of an array</a></li><li><a title="How to copy an array" href="/FAQ/content/6/30/en/how-to-copy-an-array.html">How to copy an array</a></li><li><a title="Passing arrays to functions" href="/FAQ/content/6/32/en/passing-arrays-to-functions.html">Passing arrays to functions</a></li></ul>
</div>
</section>
<section class="well">
<header>
<h3>Tags</h3>
</header>
<div id="tagcloud-content">
<div id="tagcloud-content"><span class="relevance4"><a title="Arduino (4)" href="/FAQ/tags/1/arduino.html">Arduino</a> </span><span class="relevance5"><a title="array (5)" href="/FAQ/tags/35/array.html">array</a> </span><span class="relevance1"><a title="assignment (1)" href="/FAQ/tags/83/assignment.html">assignment</a> </span><span class="relevance1"><a title="C (1)" href="/FAQ/tags/95/c.html">C</a> </span><span class="relevance2"><a title="C++ (2)" href="/FAQ/tags/36/c.html">C++</a> </span><span class="relevance1"><a title="C++11 (1)" href="/FAQ/tags/88/c11.html">C++11</a> </span><span class="relevance1"><a title="class (1)" href="/FAQ/tags/3/class.html">class</a> </span><span class="relevance1"><a title="compile (1)" href="/FAQ/tags/94/compile.html">compile</a> </span><span class="relevance1"><a title="copy (1)" href="/FAQ/tags/96/copy.html">copy</a> </span><span class="relevance2"><a title="delete (2)" href="/FAQ/tags/18/delete.html">delete</a> </span><span class="relevance4"><a title="error (4)" href="/FAQ/tags/40/error.html">error</a> </span><span class="relevance1"><a title="extensions (1)" href="/FAQ/tags/48/extensions.html">extensions</a> </span><span class="relevance1"><a title="external (1)" href="/FAQ/tags/45/external.html">external</a> </span><span class="relevance1"><a title="fail (1)" href="/FAQ/tags/92/fail.html">fail</a> </span><span class="relevance1"><a title="for (1)" href="/FAQ/tags/39/for.html">for</a> </span><span class="relevance2"><a title="free (2)" href="/FAQ/tags/20/free.html">free</a> </span><span class="relevance1"><a title="function (1)" href="/FAQ/tags/130/function.html">function</a> </span><span class="relevance2"><a title="IDE (2)" href="/FAQ/tags/89/ide.html">IDE</a> </span><span class="relevance1"><a title="ifdef (1)" href="/FAQ/tags/41/ifdef.html">ifdef</a> </span><span class="relevance1"><a title="ino (1)" href="/FAQ/tags/47/ino.html">ino</a> </span><span class="relevance1"><a title="invalid (1)" href="/FAQ/tags/82/invalid.html">invalid</a> </span><span class="relevance1"><a title="libraries (1)" href="/FAQ/tags/23/libraries.html">libraries</a> </span><span class="relevance1"><a title="library (1)" href="/FAQ/tags/93/library.html">library</a> </span><span class="relevance1"><a title="loop (1)" href="/FAQ/tags/38/loop.html">loop</a> </span><span class="relevance1"><a title="main (1)" href="/FAQ/tags/42/main.html">main</a> </span><span class="relevance2"><a title="malloc (2)" href="/FAQ/tags/19/malloc.html">malloc</a> </span><span class="relevance1"><a title="modules (1)" href="/FAQ/tags/71/modules.html">modules</a> </span><span class="relevance1"><a title="monitor (1)" href="/FAQ/tags/44/monitor.html">monitor</a> </span><span class="relevance1"><a title="multiple (1)" href="/FAQ/tags/72/multiple.html">multiple</a> </span><span class="relevance2"><a title="new (2)" href="/FAQ/tags/17/new.html">new</a> </span><span class="relevance1"><a title="pointer (1)" href="/FAQ/tags/131/pointer.html">pointer</a> </span><span class="relevance2"><a title="reference (2)" href="/FAQ/tags/2/reference.html">reference</a> </span><span class="relevance1"><a title="serial (1)" href="/FAQ/tags/43/serial.html">serial</a> </span><span class="relevance1"><a title="sketch (1)" href="/FAQ/tags/81/sketch.html">sketch</a> </span><span class="relevance1"><a title="stop (1)" href="/FAQ/tags/80/stop.html">stop</a> </span><span class="relevance1"><a title="struct (1)" href="/FAQ/tags/98/struct.html">struct</a> </span><span class="relevance1"><a title="tabs (1)" href="/FAQ/tags/73/tabs.html">tabs</a> </span><span class="relevance1"><a title="ternary (1)" href="/FAQ/tags/24/ternary.html">ternary</a> </span><span class="relevance1"><a title="typedef (1)" href="/FAQ/tags/97/typedef.html">typedef</a> </span><span class="relevance2"><a title="undefined (2)" href="/FAQ/tags/4/undefined.html">undefined</a> </span><span class="relevance1"><a title="upload (1)" href="/FAQ/tags/91/upload.html">upload</a></span></div>
</div>
</section>
</div>
</div>
</section>
<footer id="footer" class="container-fluid hidden-print">
<div class="row-fluid">
<div class="span6">
<ul class="footer-menu">
<li><a href="http://arduino.land/FAQ/sitemap/A/en.html">Sitemap</a></li>
<li><a href="http://arduino.land/FAQ/contact.html">Contact</a></li>
<li><a href="http://arduino.land/FAQ/glossary.html">FAQ Glossary</a></li>
<li><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Arduino_Main -->
<ins class="adsbygoogle ad_reg_rect"
data-ad-client="ca-pub-2585293717740875"
data-ad-slot="3848155541"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></li>
</ul>
</div>
<div class="span6">
<form action="?sid=557822" method="post" class="pull-right" accept-charset="utf-8">
<select class="language" name="language" id="language" size="1" onchange="this.form.submit();">
<option value="ar">Arabic</option>
<option value="eu">Basque</option>
<option value="bn">Bengali</option>
<option value="bs">Bosnian</option>
<option value="pt-br">Brazilian Portuguese</option>
<option value="zh">Chinese (Simplified)</option>
<option value="tw">Chinese (Traditional)</option>
<option value="cs">Czech</option>
<option value="da">Danish</option>
<option value="nl">Dutch</option>
<option value="en" selected="selected">English</option>
<option value="fi">Finnish</option>
<option value="fr">French</option>
<option value="fr-ca">French (Canada)</option>
<option value="de">German</option>
<option value="el">Greek</option>
<option value="he">Hebrew</option>
<option value="hi">Hindi</option>
<option value="hu">Hungarian</option>
<option value="id">Indonesian</option>
<option value="it">Italian</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="lv">Latvian</option>
<option value="lt">Lithuanian</option>
<option value="ms">Malay</option>
<option value="nb">Norwegian Bokm&aring;l</option>
<option value="fa">Persian</option>
<option value="pl">Polish</option>
<option value="pt">Portuguese</option>
<option value="ro">Romanian</option>
<option value="ru">Russian</option>
<option value="sr">Serbian</option>
<option value="sk">Slovak</option>
<option value="sl">Slovenian</option>
<option value="es">Spanish</option>
<option value="sv">Swedish</option>
<option value="th">Thai</option>
<option value="tr">Turkish</option>
<option value="uk">Ukrainian</option>
<option value="vi">Vietnamese</option>
<option value="cy">Welsh</option>
</select>
<input type="hidden" name="action" value="" />
</form>
</div>
</div>
<div class="row">
<p class="copyright pull-right">
powered by <a href="http://www.phpmyfaq.de" target="_blank">phpMyFAQ</a> 2.8.15
</p>
</div>
</footer>
</body>
</html>