0

Hello friends,

I was trying to brush my programing skill and was not able to get answer of "why array size is different inside function solution1?" Inside main, size of array is 11 but inside solution1 its size is just 2.
Here is my code...

#include <iostream>
#include <stdio.h>
using namespace std;

void solution2(int array1[], int number)
{
}


void solution1(int array1[], int number)
{
    printf("solution1::size of array1(%Zu) and number is(%d)\n", sizeof(array1)/sizeof(int), number );
}   

int main()
{
    int number = 10;
    int array1[] = {1,2,5, 6, 4, 9, 8, 22, 13, 3, 7};
    printf("size of array1(%Zu) and number is(%d)\n", sizeof(array1)/sizeof(int), number );
    solution1(array1, number);
   return 0;
}

                                                                                                                                                   2,18          Top
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by johnray31
1

why array size is different inside function solution1?

Because the "array" in solution1 isn't an array, it's a pointer. Don't be tricked by the array-like syntax of int array[] in a function parameter declaration, it's just syntactic sugar and equivalent to int *array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.