多少元素充满C数组 [英] How many elements are full in a C array

查看:150
本文介绍了多少元素充满C数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有C中的数组,你怎么能找出其中很大一部分是如何填补?

If you have an array in C, how can you find out how much of it is filled?

推荐答案

在C数组,任何元素的对象。其中,您有首先必须被分配以指向对象的引用它不是用Java喜欢。凡是用C行为像Java中的原始类型。

In a C array, any element is an object. It's not like in Java where you have references that first have to be assigned to point to objects. Anything in C behaves like a primitive type in Java.

如果您有C指针数组,您可以查看此相似的东西如何在Java中的工作。您可以使用空指针来指定不填充指向一个对象

If you have an array of pointers in C, you may view this similar to how things in Java work. You can use null pointers to designate "is not filled to point to an object":

// creates an array of 10 pointers, and initializes all of
// them to null pointers. If you leave off "{ 0 }", you 
// have to manually initialize them!
struct foo *array[10] = { 0 };

然后,你可以简单地用

Then you can simply test with

if(array[i] == 0) {
  printf("Position %d does not point to an object!\n", i);
}

这篇关于多少元素充满C数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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