Passed array inconsistent bahevior; C++ -
this question has answer here:
- using sizeof on arrays passed parameters [duplicate] 4 answers
- what array decaying? 7 answers
i'm trying learn basic c++ , moment started think got grasp of pointers stumbled across problem:
int sizeof(string texts[]) { return sizeof(texts); } int main() { string texts[] = {"apple", "banana", "orange", "watermelon"}; cout << sizeof(texts) << endl; cout << sizeof(texts) << endl; }
and function returns
128 8
my question is: happening when pass array argument? why c++ forgets array? have tried dereference inside method (return sizeof(*texts)
) returned 32
instead size of 1 string element, not whole array. possible want do? mistaken?
Comments
Post a Comment