I wrote a simple program that takes in 5 numbers into an array and then spits them back at you. Except that if the number inputted by the user is less than 10, it is doubled.
Simple enough. What I don't understand is why when I run the sizeof() function in my doubleA function, it returns the size of the array as 4. I assume it has something to do with its int value, but the sizeof() works fine in the main().
Halp?
Code:
#include <stdio.h>
void doubleA(int a[]);
main()
{
int array[5];
int i;
printf("Please enter 5 numbers: ");
for(i=0; i<5; i++)
scanf("%d", &array[i]);
// My custom function
doubleA(array);
for(i=0; i<5; i++)
printf("The %d number you printed was %d\n", i+1, array[i]);
// prints sizeof() the array
printf("size of array[] in main() function: %d\n", sizeof(array));
}
void doubleA(int a[])
{
int i, arraysize;
arraysize = sizeof(a)/sizeof(int);
//prints sizeof() the array
printf("size of a[] in doubleA = %d\n", sizeof(a));
for (i=0; i<5; i++)
if (a[i] <10)
a[i] *= 2;
}