如何在C ++中获取动态分配的int数组的大小 [英] How to get size of a dynamic allocated array of ints in C++

查看:39
本文介绍了如何在C ++中获取动态分配的int数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取C ++中动态分配的int数组的大小?

How to get size of a dynamic allocated array of ints in C++?

示例:(/这将始终将4设为4 * 8 = 32位,它是int的大小)

Example:(/this will always give 4 as 4 * 8 = 32bits it's size of int)

bool tabSum(int* t, int& p, int& np){
   cout<<"\n\n";
   cout<<sizeof(*t)<<endl;
}

推荐答案

您不能将数组作为参数传递给指针.而 sizeof 是一个编译时运算符.

You can't, arrays decay to pointers when passed as parameters. And sizeof is a compile-time operator.

我建议您改用 std :: vector .

这篇关于如何在C ++中获取动态分配的int数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆