欢迎光临散文网 会员登陆 & 注册

size() and sizeof() in c++

2023-07-03 13:39 作者:Euler_Formula  | 我要投稿

`size()` and `sizeof()` are two different things in C++. `size()` is a member function of the vector class and other container classes in C++, which returns the number of elements in the container. For example, to get the size of a vector `v`, you would call `v.size()`. This function is useful for getting the number of elements in a container at runtime, as it depends on the actual data stored in the container. `sizeof()` is an operator in C++, which computes the size in bytes of a data type or a variable. For example, to get the size of an integer `x`, you would call `sizeof(x)`. This operator is useful for getting the size of a data type or a variable at compile time, as it does not depend on the value of the data stored in the variable. So, in summary: - `size()` is a member function of container classes in C++, which returns the number of elements in the container at runtime. - `sizeof()` is an operator in C++, which computes the size in bytes of data types or variables at compile time. It does not work on container classes like vectors.

size() and sizeof() in c++的评论 (共 条)

分享到微博请遵守国家法律