Why function does not know the array size?

后端 未结 8 2313
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 21:04

If I write

int main()
{
    int a[100] = {1,2,3,4,};
    cout<

        
8条回答
  •  情书的邮戳
    2021-01-26 21:40

    No. You are wrong.

    If I run your second part of code, it gives 1 on my computer. It's not 400.

    #include 
    
    void func(int *a);
    
    using namespace std;
    
    int main()
    {
        int a[100] = {1,2,3,4,};
        func(a);
        return 0;
    }
    
    void func(int *a)
    {
         cout<

    Produces

    1
    

提交回复
热议问题