整数数组 [英] integer array

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

问题描述



int * p;

p ++;这里p现在以整数大小递增自身。


同样,
我想知道,如何声明一个指向数组的指针(比如说数组)

整数)

其中我们做了一个p ++,每当它增加1时,它会以

数组的大小递增。

喜欢

p ++;即p = p + 1; //如果10是数组的大小,则应该以10递增。


指向数组的指针应该增加指针的大小

每次增加一个数组1.我们可以声明这样一个

指针吗?


一个可能的解决方案就是


#define SIZE_ARRAY

int * p [SIZE_ARRAY] [SIZE_ARRAY];


//增加指针与数组的大小。


p = p + SIZE_ARRAY; //每次增加大小。


但这并没有声明一个指向数组的指针,因为它只是移动到

下一个位置如果我们这样做p = p + 1;

我知道数组不是原始数据类型。但有没有办法呢?
呢?

解决方案

sh *********** @ sify.com 写道:

int * p;
p ++;这里p现在以整数的大小递增自身。同样,
,我想知道,如何声明一个指向数组的指针(比如
整数数组)
在其中我们做一个p ++它随着大小增加自己
数组每增加1个
数组。
p ++;即p = p + 1; //如果10是数组的大小,则应该以10递增。
指向数组的指针应该在每次增加1时使用数组大小​​增加指针。我们可以声明这样的指针吗?
一个可能的解决方案是
#define SIZE_ARRAY
int * p [SIZE_ARRAY] [SIZE_ARRAY];




不,那个将是一个int指针的二维数组。


你需要的是(我认为)这样的东西:


int a [ SIZE_ARRAY_1] [SIZE_ARRAY_2];

int(* p)[SIZE_ARRAY_2] =& a [0];


因为那是指针的指针大小为SIZE_ARRAY_2的int数组。

p ++不是指向[1]等的指针。


问候,Jens

-

\ Jens Thoms Toerring ___ Je **** *******@physik.fu-berlin.de

\ __________________________ http://www.toerring.de


sh *********** @ sify.com 在留言新闻中写道:< 62 ************* *************@posting.google。 com> ...


int * p;
p ++;这里p现在以整数的大小递增自身。


否,p随数据指针的大小递增。你是什​​么

说的是sizeof(int)== sizeof(int *)这不一定是真的,

而且我不认为这是什么你想说的。

同样,
我想知道,如何声明一个指向数组的指针(比如
整数数组)
在哪里我们做一个p ++,每当它增加1时,它就会以
数组的大小递增。
就像
p ++;即p = p + 1; //如果10是数组的大小,则应该以10递增。




不可能。您要求的是自定义指针。

数据指针和函数指针是实现定义的,而不是用户定义的



您可以使用指针指针...


int * p [3];


设置* p [0] ,* p [1]和* p [2]指向不同的数组。现在p ++将

依次引用每个数组的开头。


问候,

Mark。




< sh *********** @ sify.com>在消息中写道

news:62 ************************** @ posting.google.c om ...


int * p;
p ++;这里p现在以整数的大小递增。

类似地,
我想知道,如何声明一个指向数组的指针(比如
整数数组)
其中我们做了一个p ++,每当它增加1时,它就会随着
数组的大小递增。
就像
p ++;即p = p + 1; //如果10是数组的大小,则应该以10递增。

指向数组的指针,应该每次增加指针的大小为
数组我们可以声明这样一个指针吗?



#define SIZE_ARRAY
int * p [SIZE_ARRAY ] [SIZE_ARRAY];

//用数组大小​​递增指针。

p = p + SIZE_ARRAY; //每次都用大小递增。

但这并没有声明一个指向数组的指针,因为它只是移动到下一个位置,如果我们做p = p + 1;
我知道数组不是原始数据类型。但有没有办法呢?




struct p_size_array {int p [SIZE_ARRAY];};


这个(特殊限制情况)结构的指针应该在你列出的

方法中表现。


Michael Steve


Hi,
int *p;
p++; here p now increments itself with the size of integer.

similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it increments itself with the size of the
array each time it is incremented with 1.
like
p++; ie p = p + 1; // should increment with 10 if 10 is the size of
the array.

The pointer to an array, should increment the pointer with the size of
an array each time it is incremented with 1. Can we declare such a
pointers ?

one probable solution for this is

#define SIZE_ARRAY
int *p[SIZE_ARRAY][SIZE_ARRAY];

// to increment the pointer with the size of the array.

p = p + SIZE_ARRAY; // increment each time with the size.

but this does not declare a pointer to array as it simply moves to
next location if we do p = p + 1;
I know array is not the primitive data type. but is there a way to do
it ?

解决方案

sh***********@sify.com wrote:

int *p;
p++; here p now increments itself with the size of integer. similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it increments itself with the size of the
array each time it is incremented with 1.
like
p++; ie p = p + 1; // should increment with 10 if 10 is the size of
the array. The pointer to an array, should increment the pointer with the size of
an array each time it is incremented with 1. Can we declare such a
pointers ? one probable solution for this is #define SIZE_ARRAY
int *p[SIZE_ARRAY][SIZE_ARRAY];



No, that would be a two-dimensional array of int pointers.

What you need is (I think) something like this:

int a[ SIZE_ARRAY_1 ][ SIZE_ARRAY_2 ];
int ( *p ) [ SIZE_ARRAY_2 ] = &a[ 0 ];

because that''s a pointer to an int array of size SIZE_ARRAY_2.
p++ would than be a pointer to a[ 1 ] etc.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de


sh***********@sify.com wrote in message news:<62**************************@posting.google. com>...

Hi,
int *p;
p++; here p now increments itself with the size of integer.
No, p is incremented with the size of a data pointer. What you''re
saying is sizeof(int) == sizeof(int *) which is not necessarily true,
and I don''t think this is what you meant to say.

similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it increments itself with the size of the
array each time it is incremented with 1.
like
p++; ie p = p + 1; // should increment with 10 if 10 is the size of
the array.



Not possible. What you''re asking for are custom-defined pointers.
Data pointers and function pointers are implementation defined, not
user defined.

You could use pointers to pointers ...

int *p[3];

Set *p[0], *p[1] and *p[2] to point to different arrays. Now p++ will
reference the start of each array in turn.

Regards,
Mark.



<sh***********@sify.com> wrote in message
news:62**************************@posting.google.c om...

Hi,
int *p;
p++; here p now increments itself with the size of integer.

similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it increments itself with the size of the
array each time it is incremented with 1.
like
p++; ie p = p + 1; // should increment with 10 if 10 is the size of
the array.

The pointer to an array, should increment the pointer with the size of
an array each time it is incremented with 1. Can we declare such a
pointers ?

one probable solution for this is

#define SIZE_ARRAY
int *p[SIZE_ARRAY][SIZE_ARRAY];

// to increment the pointer with the size of the array.

p = p + SIZE_ARRAY; // increment each time with the size.

but this does not declare a pointer to array as it simply moves to
next location if we do p = p + 1;
I know array is not the primitive data type. but is there a way to do
it ?



struct p_size_array {int p[SIZE_ARRAY];};

A pointer of this (special limited case of) struct should then behave in the
method you have listed.

Michael Steve


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

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