English 中文(简体)
A. 结构的初始点
原标题:Initializing structure pointer with array of structure

我有以下疑问:

I have a structure array. Before I had it initialized directly and was using in my code. But I was suggested to use pointers instead of direct structure. But I cannot get the pointer pointing to the array of structre properly.

typedef struct 
{
    int a;
    int b;
} cqiReport;


cqiReport s_cqiReport[2][2];    
cqiReport *ptr[2], *ptr2, *ptr3;
s_cqiReport[0][0].a=1;
s_cqiReport[0][0].b=1;
*ptr= s_cqiReport;
    *ptr2= s_cqiReport[0][0];
    *ptr3= s_cqiReport[1][0];

I get ptr[0] pointing to s_cqiReport[0][0] properly but ptr[2] points to some junk. How do i get ptr2[1] point to s_cqiReport[1][0]?

Please Help Thanks DSP guy

问题回答

奥凯就是这种东西。 You ve got s_cqiReport as a multi range and ptr as a one-dimensioned. 段 次

*ptr = s_cqiReport 

没有什么意义。

此外,你还把任何东西推入了实际的“血清报告”。

如下。

cqiReport *foo = new cqiReport;
foo->a = 9;
foo->b = 3;

这回答了你的问题,但应该有所帮助。

你们必须认识到的是,一个阵列实际上是一个点,例如<条码>*ptr。 <代码>s_cqiReport[0][0],因为它等于s_cqiReport。 这本身就是一个要点。

现在,如果你想让你的点子指明价值,那么你就必须使用<代码>和>;的操作者,这主要是“解决”,例如<代码>ptr3=和amp;s_cqiReport[0]就使你想到这一点的点。

同样,我认为,<条码>ptr3 = s_cliReport + 2还将造成ptr3,指出你似乎想到这一点,但我将避免在你对点人及其工作方式有强烈了解之前,对点人进行算术。





相关问题
WordPress Data Storage Efficiency

I ve been asked to review a WordPress plugin of sorts and try to find ways of making it faster. The premise of this plugin is basically to store a bunch of users and shifts and appointments and ...

Convert a 2D array index into a 1D index

I have two arrays for a chess variant I am coding in java...I have a console version so far which represents the board as a 1D array (size is 32) but I am working on making a GUI for it and I want it ...

Convert an array of integers for use in a SQL "IN" clause

Surely there is a framework method that given an array of integers, strings etc converts them into a list that can be used in a SQL "IN" clause? e.g. int[] values = {1,2,3}; would go to "(1,2,3)"

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

Best practice of big javascript objects

sry for this imprecise topic name. I am querying a dataset a lot of times so using ajax request would end up in tons of http requests. For this reason I decided to use the json encode method to ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

热门标签