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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...