Pointer and array
1.How is memory laid out for a program?
Memory is divided into blocks of a certain size (32-bits or 64-bits depending on the OS)
Each block has a specified address
This means every location in memory can be accessed by using its address
變數是參照某位置, 值是儲存該位置的值
pointer是指向某位置, 值是儲存該位置
int radius = 25;
int *rasdiudPtr = &radius;
int *otherRsdiudPtr;
otherRsdiudPtr = rasdiudPtr;
int r = *rasdiudPtr;
printf("%u\n", &radius); //123FF
printf("d\n", *&radius); //25
printf("%d\n", *rasdiudPtr); //25
printf("%u\n", rasdiudPtr); //11DA
printf("%u\n", &radiusPtr); //123FF
printf("%u\n", &otherRsdiudPtr); //AB242.Why pointer need a type?
How mush space does stuff occupy
Integer: 4 bytes
Float: 4 bytes
Char: 1 bytes
3.Arrays in C are actually pointers
Array variables are simply pointers
int *: arr is a pointer to an integer and it points to the address location of the very first element in the integer array
4.Problem 1
5.Problem 2
6.Problem 3
7.Problem 4
Last updated