Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

c - 2 dimensional array simple understanding

I have some old code of mine which i dont understand why i did some thing . I have a pointer which is int_16t *q, of 1024 ints . now i am trying to copy it with :

       buffersRing[ringNum][0]=inNumberFrames;
       memcpy(buffersRing[ringNum]+1, q, inNumberFrames * sizeof *q); 

when first place in array is some int variable, and all other place after that are q.

But, why i havnt done that(and whats the difference ) :

    buffersRing[ringNum][0]=inNumberFrames;
    memcpy(buffersRing[ringNum][1], q, inNumberFrames * sizeof *q); 

Is it trying to put all q ints into the first place in array ? or is it the same?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No,

buffersRing[ringNum]+1 // refers to a pointer to an array element

is not the same as

buffersRing[ringNum][1] // refers to the actual array element

The first one is the one you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...