c++ - Can't understand a sentence about c dynamic memory allocation?
代言
代言 2017-06-20 10:06:25
0
1
621
char *data; int leng=0; data = (char *)malloc(nFileLen); for (int i = 0; (aa = fgetc(fp)) != EOF;i++) { data[i] = aa; leng++; }

I don’t understand how to operate like this after dynamically allocating memory. Can you explaindata[i]=xxxI don’t understand this sentence
and when I use it, I use*dataonly outputs one character
, but using the loopdata[i]can output a lot. I’m wondering if it’s not*data[i]

代言
代言

reply all (1)
为情所困
data为char *类型指针,可以以数组下标形式访问,指针+偏移,data[i]等价于*(data + i)
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!