【发布时间】:2015-02-13 19:53:21
【问题描述】:
我想在 (0 - a) 范围内创建随机数,并用指针 b 和 c 返回它们。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void random (int a, int *b, int *c)
{
srand(time(0));
*b = rand()%(a+1);
*c = rand()%(a+1);
printf("%i%i", *b, *c);
}
int main()
{
int a = 10; // upp
int* b;
int* c;
random (a, b, c);
}
代码有效,尽管我的可执行文件在 random() 之后立即崩溃。
知道为什么会崩溃吗?
【问题讨论】:
-
b和c是指针...您需要先将它们指向某些东西,然后才能取消引用它们