指针数组 [英] array of pointers
问题描述
嗨
关于指针数组的问题。
以下是一个21元素的数组,每个都是一个指针
或者这是一个指向ONE数组的指针(听起来很奇怪):
double * ydata [21];
假设这是21个指针我如何初始化
它们指向null?这是错的:
,i = 0; i = 20 i ++
ydata [i] = NULL;
并稍后在某处分配新的
for I = 0; i = 20 i ++
ydata [i] = new double [1000];
这曾经在C中工作,但不适用于C ++!
分配新的后我试试这个:
for(int i = 0; i< 1000; i ++){
ydata [0] [i] = double (rev_data [i]);
它只是崩溃。
为你的帮助提供
Kamran
< br>
请参阅多维阵列上的faq部分
Raj
AFAIR
T * p [n]; //数组T *
T(* p)[n]; //指针T [n]
* Henrietta Denoue:
嗨
以下是一个21元素数组,每个都是一个指针
或者这是一个指向ONE数组的指针(听起来很奇怪)
double * ydata [21];
一个21元素的数组,每个元素都是一个指针。
假设这是21个指针我如何初始化
他们指向null?这是错的:
对于i = 0; i = 20 i ++
ydata [i] = NULL;
是的,这是错误的,无论是语法上(它不是C ++)还是意图。
最简单的方式是
double * ydata [21] = {};
并分配新的某处后来
对于i = 0; i = 20 i ++
ydata [i] = new double [1000];
这曾经在C中工作,但不适用于C ++!
从来没有用过C语言,它既不是C语言也不是C ++语法。
分配新语后我试试这个:
for(int i = 0; i< 1000; i ++){
ydata [0] [i] = double(rev_data [i]);
At只是崩溃了。
将该循环与之前的循环进行比较。
-
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么这么糟糕?
A:热门发布。
问:usenet和电子邮件中最烦人的事情是什么?
Hi
A question about array of pointers.
Is the following an 21 element array, each a pointer
or is this a pointer to ONE array (strange as it sounds):
double* ydata[21];
And supposing this to be 21 pointers how do I initialize
them to point to null ? Is this wrong:
for i=0; i=20 i++
ydata[i] = NULL;
and to allocate new somewhere later
for i=0; i=20 i++
ydata[i] = new double[1000];
This used to work in C but doesn''t with C++ !
After allocating new I try this:
for (int i = 0; i < 1000; i++) {
ydata[0][i] = double(rev_data[i]);
At it just crashes.
Thaks for your help
Kamran
please see the faq section on multi-dimensional array
Raj
AFAIR
T *p[n]; //array of T*
T (*p)[n]; //pointer to T[n]
* Henrietta Denoue:
Hi
A question about array of pointers.
Is the following an 21 element array, each a pointer
or is this a pointer to ONE array (strange as it sounds)
double* ydata[21];
A 21 element array, each element a pointer.
And supposing this to be 21 pointers how do I initialize
them to point to null ? Is this wrong:
for i=0; i=20 i++
ydata[i] = NULL;
Yes, that is wrong, both syntactically (it''s not C++) and in intent.
Easiest way is
double* ydata[21] = {};
and to allocate new somewhere later
for i=0; i=20 i++
ydata[i] = new double[1000];
This used to work in C but doesn''t with C++ !
That has never worked in C, it''s neither C nor C++ syntax.
After allocating new I try this:
for (int i = 0; i < 1000; i++) {
ydata[0][i] = double(rev_data[i]);
At it just crashes.
Compare that loop to the previous ones.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
这篇关于指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!