真的很基础.. [英] Really basic..

查看:77
本文介绍了真的很基础..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义喜欢,


浮动**数据;


那么就不能在我的程序中执行此操作..


data [0] [0] = 23.23;


为什么这总是会给出某种内​​存错误..


#include" stdio.h"

int main()

{

float ** data;

data [0] [0] = 23.23;

返回0;


}


我错过了一些令人讨厌的事情...


提前感谢。

解决方案



deepak写道:

如果我定义喜欢,

浮动**数据;

然后可以我在我的程序中这样做..

数据[0] [0] = 23.23;

为什么这总是会给出某种内​​存错误..

#include" stdio.h"
int main()
{/>浮动**数据;
数据[0] [0] = 23.23;
返回0;

}

我错过了一些充满希望的东西ing ...




是的。你没有为你的数据分配任何内存。


浮动**数据;


只声明一个指向数据位置的指针是,没有分配内存。


尝试:


#include< stdlib.h>

。 ..


data = malloc(N_ROWS * N_COLS * sizeof ** data);


if(data == NULL)/ * do关于错误的事情* /;

...




Vladimir Oka写道:< blockquote class =post_quotes> deepak写道:

如果我定义喜欢,

浮动**数据;

那么就不能做这在我的程序中..

数据[0] [0] = 23.23;

为什么这总是会给出某种内​​存错误..

#include" stdio.h"
int main()
{
浮动**数据;
数据[0] [0] = 23.23;
返回0;

}
我错过了一些不可思议的事情......



是的。你没有为你的数据分配任何内存。

浮动**数据;

只声明一个指向数据所在位置的指针,没有分配内存。 br />
尝试:

#include< stdlib.h>
......

数据= malloc(N_ROWS * N_COLS * sizeof * *数据);

if(data == NULL)/ *对错误做些什么* /;
...




显然,你还需要`#define` N_ROWS和N_COLS。


deepak写道:

如果我定义喜欢,

浮动**数据;

那么就不能在我的程序中这样做..

data [0] [0] = 23.23;




您已经说过变量`data`可能包含一个指向

浮点数指针。你没有(即使是在破解的代码中)将这样的值b / b
放入其中。今天BOOM。


你需要阅读`malloc`和指针。


-

Chris "导引头" Dollin

伸出隐藏在网络中的镜子。 - 文艺复兴,/奔跑/


if i define like,

float **data;

then can''t i do this in my programm..

data[0][0]=23.23;

why this is alway giving some kind of memory error..

#include "stdio.h"
int main()
{
float **data;
data[0][0]=23.23;
return 0;

}

am i missing something fudamental thing...

thanks in advance.

解决方案


deepak wrote:

if i define like,

float **data;

then can''t i do this in my programm..

data[0][0]=23.23;

why this is alway giving some kind of memory error..

#include "stdio.h"
int main()
{
float **data;
data[0][0]=23.23;
return 0;

}

am i missing something fudamental thing...



Yes. You''re failing to allocate any memory for your data.

float **data;

only declares a pointer to where your data is, no memory is allocated.

Try:

#include <stdlib.h>
...

data = malloc( N_ROWS * N_COLS * sizeof **data);

if (data == NULL) /* do something about the error */;
...



Vladimir Oka wrote:

deepak wrote:

if i define like,

float **data;

then can''t i do this in my programm..

data[0][0]=23.23;

why this is alway giving some kind of memory error..

#include "stdio.h"
int main()
{
float **data;
data[0][0]=23.23;
return 0;

}

am i missing something fudamental thing...



Yes. You''re failing to allocate any memory for your data.

float **data;

only declares a pointer to where your data is, no memory is allocated.

Try:

#include <stdlib.h>
...

data = malloc( N_ROWS * N_COLS * sizeof **data);

if (data == NULL) /* do something about the error */;
...



Obviously, you''d need to `#define` N_ROWS and N_COLS as well.


deepak wrote:

if i define like,

float **data;

then can''t i do this in my programm..

data[0][0]=23.23;



You''ve said "the variable `data` may hold a value which is a pointer to
pointer to float". You haven''t (even in the snipped code) put such a
value into it. BOOM today.

You need to read up on `malloc` and pointers.

--
Chris "seeker" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/


这篇关于真的很基础..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆