本文介绍了如何找出C ++/C中是否已填充指针数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有功能

其中pa从[0]填充到[100]或者pa仅填充为[0].

where pa is either populated from [0] to [100]ORpa is populated for [0] only.

我的功能执行以下操作:

My function does the following:

{

IF(pa是100的数组)则x [0到100] = pa [0到100]

IF (pa is an array of 100) THEN x[0 to 100] = pa[0 to 100]

ELSE x [0至100] = pa [0]

ELSE x[0 to 100] = pa[0]

}

推荐答案

问:foo()如何知道pa []是否为100的数组?

Q: How is foo() going to know whether pa[] is an array of 100?

通常,您必须告诉它.例如:

In general, you have to TELL it. For example:

void
foo (double *pa, int len)
{
  if (len == 100)
    ...
  else
    ...

但是,如果您使用C ++进行编码,则可以使用STL容器,例如矢量:

If you were coding in C++, however, you could use an STL container such as a vector:

void foo (vector<double> & pa)
{
  if (pa.size() == 100)
    ...

这篇关于如何找出C ++/C中是否已填充指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:36