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

Home
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
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.