#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int i,L
char *p
void main() {
for (i=0i<20000i++) {
L=rand()
p=malloc(L)
if (NULL==p) {
printf("malloc error!\n")
continue
}
memset(p,0,L)
free(p)
}
}
//不使用动态分配
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define MAXLEN 30000
int i,L
char buf[MAXLEN]
char *p
void main() {
p=&buf[0]
for (i=0i<20000i++) {
L=rand()
if (L>MAXLEN) {
printf("L>MAXLEN==%d, ignore spilth.\n",MAXLEN)
L=MAXLEN
}
memset(p,0,L)
}
}
c语言定义一个行向量的方法如下:在C ++中创建一个行向量,该行向量具有从0到N的整数元素(我在C ++程序中分配的整数变量).我已经看过Armadillo C ++库并尝试使用其span函数,但是它没有创建矢量(而是创建了类型为arma::span的对象)。还可以在编译时使用std::integer_sequence和一些元编程。