0
(c++) what is the difference between passing an array to a function then finding its length and directly finding its length?
Each is giving a different output.. How to fix this problem? https://code.sololearn.com/c7EmmsCBKYL3/?ref=app
5 Antworten
+ 1
Abhishek Mazumder It's because arrays are treated as pointers in C whereas they actually are not. So when you pass array as an argument where the parameter is a pointer, what you do is sizeof( int * ) / sizeof ( int ) which makes the answer same no matter what the size of the actual array is. In my system it outputs 2 all the time as a pointer to an integer is 8 bytes and an integer is 4 bytes.
0
but each is giving a different output
0
ok got it Thanks
0
but come we find the size of an array inside a function
0
Mustafa K. Thank You very much I found it..