Passing arrays and individual array elements to functions : Array Parameter « Array « C Tutorial

C Tutorial
1. Language
2. Data Type
3. String
4. printf scanf
5. Operator
6. Statement
7. Array
8. Function
9. Structure
10. Pointer
11. Memory
12. Preprocessor
13. File
14. Data Structure
15. Search Sort
16. Wide Character String
17. assert.h
18. ctype.h
19. math.h
20. setjmp.h
21. signal.h
22. stdio.h
23. stdlib.h
24. string.h
25. time.h
26. wctype.h
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C Tutorial » Array » Array Parameter 
7. 7. 2. Passing arrays and individual array elements to functions
#include <stdio.h>
#define SIZE 5

void modifyArrayint b[]int size )
void modifyElementint );

int main()
{
   int aSIZE 0123}
   int i; 

   printf"Effects of passing entire array by reference:\n\nThe "
          "values of the original array are:\n" );

   for i = 0; i < SIZE; i++ ) { 
      printf"%3d", a] );
   

   printf"\n" );

   modifyArraya, SIZE );  

   printf"The values of the modified array are:\n" );

   for i = 0; i < SIZE; i++ ) {
      printf"%3d", a] );
   

   printf"\n\n\nEffects of passing array element "
           "by value:\n\nThe value of a[3] is %d\n", a] );
   
   modifyElementa] )

   printf"The value of a[ 3 ] is %d\n", a] );
   
   return 0

}

void modifyArrayint b[]int size )
{
   int j; 

   for j = 0; j < size; j++ ) {
      b*= 2;
   

}

void modifyElementint )
{
   printf"Value in modifyElement is %d\n", e *= );
}
Effects of passing entire array by reference:

The values of the original array are:
  0  1  2  3  4
The values of the modified array are:
  0  2  4  6  8


Effects of passing array element by value:

The value of a[3] is 6
Value in modifyElement is 12
The value of a[ 3 ] is 6
7. 7. Array Parameter
7. 7. 1. Pass array to function
7. 7. 2. Passing arrays and individual array elements to functions
w___w___w_._j___a___v___a__2__s___.___c_o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.