开发者

returning address form a function

开发者 https://www.devze.com 2023-02-11 15:09 出处:网络
i have returned address form a function search(keys), like this return ptr->keys[pos] where ptr->keys[pos].value was used to access the member function of keys. is the above return statement co

i have returned address form a function search(keys), like this

return ptr->keys[pos]

where ptr->keys[pos].value was used to access the member function of keys. is the above return statement correct? does this return the address after it returns i have done

struct classifier keys,temp,*temp_pt开发者_JS百科r;
temp = search(key);
temp_ptr = &temp;

and then i am accessing the member function value of keys as

temp->value


From what you've said, if pos is 0 or 1 then it's a valid index in keys and the return statement is ostensibly correct. Please post realistic code though: the question's "struct classifier keys,..." is not reconcilable with "struct classifier keys[2]" mentioned in your comment above. The following code is not correct: temp = search(key); tries to copy a pointer into a structure. You might mean temp = *search(key), which will copy the struct classifier's content out. You can then use temp.value or temp_ptr->value but NOT temp->value as you asked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号