请教大家关于指针存储的问题,

来源:百度知道 编辑:UC知道 时间:2024/05/31 14:12:29
让大家帮我看看一段代码得 一小块:/* Program 7.11 A dynamic prime example */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void)
{
unsigned long *primes = NULL; /* Pointer to primes storage area */
unsigned long trial = 0; /* Integer to be tested */

bool found = false; /* Indicates when we find a prime */
size_t total = 0; /* Number of primes required */
size_t count = 0; /* Number of primes found */

printf("How many primes would you like - you'll get at least 4? ");
scanf("%u", &total); /* Total is how many we need to find */
total = total<4U ? 4U:total; /* Make sure it is at least 4 */

/* Allocate sufficient memory to store the number of primes required */
primes = (unsigne

指针存储的是地址,但指向的是数据,比如:int *a=1;也就是说,定义了a是指针,是个地址,地址是一个16进制的数,但a这个地址指向了一个存储1这个的地址,每个数据都用一个指针(地址)表示,比如1的地址是ff5,那么a的值就是ff5,*a表示指向了1这个地址,你还是把分给我吧,我写了这么多,我急需分呀,谢谢.

unsigned long *primes = NULL;是定义的指针,这个指针名字是primes,它不指向谁。
primes = (unsigned long *)malloc(total*sizeof(unsigned long)); 这儿让它指向了分配的一块内存空间
后面再使用*primes就是这个指针指向的地址里面存放的数值了