我正在尝试制作一些c程序,我坚持使用malloc命令.这是我的代码:
#include <stdlib.h>
#include <iostream>
#include "Oef1.h"
using namespace std;
some methode clled by main{
int ** q=NULL;
int m=read(q);
}
int read(int ** q){
int m=3;
int n=5; //n and m are beeing asked, but for debugging hard-coded
cout << sizeof(int*) << endl; // returns 4
cout <<sizeof(q) << endl; //returns 4
cout <<m*sizeof(int*) << endl; //returns 12
q=(int**)realloc(q,m*sizeof(int*));
cout <<sizeof(q) << endl; //should return 12 but returns 4
for(int k =0; k < m; k++){
q[k] = (int*)malloc(n*sizeof(int)); …Run Code Online (Sandbox Code Playgroud)