由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q78: about sizeof
相关主题
32bit vs 64 bitC++ Q35: sizeof() (B20_20)
O(N) sort integer arrayA malloc/free question using C/C++
details 2nd smallest element in an array问一个C的简单问题
Question:Given a array,find out if there exist a subarray such its sum is zeroc++ grill - how to dynamically allocate memory on stack?
一道 C++ 的题。菜鸟问个C++的pointer问题
C++里get array size的问题请教一道题
C++ Q93 - Q95a small question about c++ object allocation
How to find the size of an array? Thanks.算法题目一问
相关话题的讨论汇总
话题: sizeof话题: array话题: int话题: q78话题: c++
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
If an integer array is defined as the following
int* intPtr=new int[100];
How to use the sizeof() function to get the size of the integer array?
S**I
发帖数: 15689
2
you can't

【在 c**********e 的大作中提到】
: If an integer array is defined as the following
: int* intPtr=new int[100];
: How to use the sizeof() function to get the size of the integer array?

n**e
发帖数: 116
3
sizeof(intPtr)/sizeof(int)
n**e
发帖数: 116
4
Forget my last post. It is not correct.
f****4
发帖数: 1359
5
说个题外话
当你new int[]的时候,那个内存区域应该有地方标记了内存范围,或者是元素个数吧
?不然的话delete[]怎么才能释放正确的内存范围呢?

【在 S**I 的大作中提到】
: you can't
S**I
发帖数: 15689
6
yes, but that's implementation defined, there is no portable way to get the
size of a dynamically allocated array.

【在 f****4 的大作中提到】
: 说个题外话
: 当你new int[]的时候,那个内存区域应该有地方标记了内存范围,或者是元素个数吧
: ?不然的话delete[]怎么才能释放正确的内存范围呢?

f****4
发帖数: 1359
7
谢谢,我估计也是没统一的实现的关系

the

【在 S**I 的大作中提到】
: yes, but that's implementation defined, there is no portable way to get the
: size of a dynamically allocated array.

R****i
发帖数: 104
8
有记录。
不过sizeof()是编译时运行的函数,所以不能用来得到new 的size。
ref: http://shangshufu.blogspot.com/2011/08/tips-about-sizeof-function-in-c-and-c.html

【在 f****4 的大作中提到】
: 说个题外话
: 当你new int[]的时候,那个内存区域应该有地方标记了内存范围,或者是元素个数吧
: ?不然的话delete[]怎么才能释放正确的内存范围呢?

b*****i
发帖数: 262
9
sizeof is not a function.
f*******t
发帖数: 7549
10
int array[] = { 1, 2, 3, 4 };
you can get array length by sizeof(array)/sizeof(int)
if the array is dynamically allocated, you can't get its length
1 (共1页)
进入JobHunting版参与讨论
相关主题
算法题目一问一道 C++ 的题。
bloomberg onsiteC++里get array size的问题
我在微软做interviewer的经验C++ Q93 - Q95
google youtube interview, 莫名被拒。。。。。。How to find the size of an array? Thanks.
32bit vs 64 bitC++ Q35: sizeof() (B20_20)
O(N) sort integer arrayA malloc/free question using C/C++
details 2nd smallest element in an array问一个C的简单问题
Question:Given a array,find out if there exist a subarray such its sum is zeroc++ grill - how to dynamically allocate memory on stack?
相关话题的讨论汇总
话题: sizeof话题: array话题: int话题: q78话题: c++