目录
申请内存
#include <iostream>
using namespace std;
int main()
{
float *p;
p = (float *)malloc(3);
cout << p << endl;
free(p);
}
0x7fc10090d9b0
赋值
#include <iostream>
using namespace std;
int main()
{
float *p;
p = (float *)malloc(3);
p[0] = 0.5;
p[1] = 1.5;
p[2] = 2.5;
free(p);
}
取值-1
#include <iostream>
using namespace std;
int main()
{
float *p;
p = (float *)malloc(3);
p[0] = 0.5;
p[1] = 1.5;
p[2] = 2.5;
cout << p[0] << endl;
cout << p[1] << endl;
cout << p[2] << endl;
free(p);
}
0.5
1.5
2.5
取值-2
#include <iostream>
using namespace std;
int main()
{
float *p;
p = (float *)malloc(3);
p[0] = 0.5;
p[1] = 1.5;
p[2] = 2.5;
cout << *p << endl;
cout << *(p+1) << endl;
cout << *(p+2) << endl;
free(p);
}
0.5
1.5
2.5
参考
-
https://blog.csdn.net/sinat_27456831/article/details/50834965
-
https://blog.csdn.net/u014546553/article/details/53609038