Home > Back-end >  Rookie help [] sizeof small problem
Rookie help [] sizeof small problem

Time:10-09

 # include 

using namespace std;

Void the Po (int a []) {
Cout}

Int main () {
Int a []=,2,3,4,5,6,7,8 {1};

Cout
Po (a);

return 0;

}



Why in the mian function and external conventional function results are different?

CodePudding user response:

In c + +, the array will never pass by value, it is passed the first element pointer (accurately, a "0"),

CodePudding user response:

 # include & lt; Iostream> 
using namespace std;

Void po_array (int (& amp; A) [8])
{
Cout}

Void po_ctr (int a [])
{
Cout}


Void main ()
{

Int a [8]=,2,3,4,5,6,7,8 {1};
CoutPo_array (a);
Po_ctr (a);
Int cc;
Cin> Cc.
}

1/f, right, c + + function USES the array as a parameter, real parameter set can't reproduce, can only be the first element of the array address as a pointer is passed to the parameter,
Can also use the reference, pay attention to the void po_array (int (& amp; A) [8]), the dimension size is omitted,

CodePudding user response:

As a parameter int a [] is equivalent to an int * a; You can try + is ok!

CodePudding user response:

On the first floor and the second and third floors said yes
The main idea is that, in this scope, sizeof can see what,
What what sizeof can see, the size is

CodePudding user response:

  • Related