コード例 #1
0
ファイル: p221.c プロジェクト: eglove/Programs
main()
{
  int a[SIZE] = {0, 1, 2, 3, 4};
  int i;

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

  for (i=0; i<=SIZE-1; i++)
    printf("%3d", a[i]);

  printf("\n");
  modifyArray(a, SIZE);  /* array a passed call by reference */
  printf("The values of the modified array are:\n");

  for (i=0; i<=SIZE-1; i++)
    printf("%3d", a[i]);

  printf("\n\n\nEffects of passing array element call "
        "by value:\n\nThe value of a[3] is %d\n", a[3]);
  modifyElement(a[3]);
  printf("The value of a[3] is %d\n",a[3]);
  return 0;
}
コード例 #2
0
ファイル: fig06_13.c プロジェクト: zedwarth/C-Programming
/* function main begins program execution */
int main ( void )
{
	int a[ SIZE ] = { 0, 1, 2, 3, 4 }; /* initialize a */
	int i; /* counter */

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

	/* output original array */
	for ( i = 0; i < SIZE; i++ ) {
		printf( "%3d", a[ i ] ) ;
	} /* end for */

	printf( "\n" );

	/* pass array a to modifyArray by reference */
	modifyArray( a, SIZE );

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

	/* output modified array */
	for ( i = 0; i < SIZE; i++ ) {
		printf( "%3d", a[ i ] );
	} /* end for */

	/* output value of a[ 3 ] */
	printf( "\n\n\nEffects of passing array elemnt "
			"by value:\n\nThe value of a[3] is %d\n", a[ 3] );

	modifyElement( a[ 3 ] ); /* pass array element a[ 3 ] by value */

	/* output value of a [ 3 ] */
	printf( "The value of a[ 3 ] is %d\n", a[ 3 ] );
	return 0; /*indicate that program ended successfully */
} /* end function main */
コード例 #3
0
ファイル: Fig6.13.c プロジェクト: Rukeith/C-Example
int main( void )
{
   int a[ SIZE ] = { 0, 1, 2, 3, 4 };
   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[ i ] );
   }

   printf( "\n" );

   modifyArray( a, SIZE );
  
   printf( "The values of the modified array are:\n" );

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

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

   modifyElement( a[ 3 ] );

   printf( "The value of a[ 3 ] is %d\n", a[ 3 ] );
   return 0;
}
コード例 #4
0
int main(int argc, const char * argv[]) {
    int size, index;
    scanf("%d", &size);
    int * inpArray = (int *)malloc(size* sizeof(int));
    for(index = 0; index < size; index++)
        scanf("%d", &inpArray[index]);
    modifyArray(inpArray, size);
    printArray(inpArray, size);
    return 0;
}