Pointer Locate

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>    /*Unix Standard 用于系统调试*/

/* P是一个指针变量的名字表示指针变量指向的内存地址,*p是所指对象的内容,&p指针p的地址*/

static void show_pointer(void *p, char *descr) {   /*参数都为指针*/
    //    printf("Pointer for %s at %p\n", descr, p);
    printf("%s\t%p\t%lu\n", descr, p, (unsigned long) p);
    /* %p表示将所指向的数据地址以十六进制的形式输出*/
}

char big_array[1L<<24];    /*  16 MB */
//char huge_array[1L<<31];   /*   2 GB */
char huge_array[1L<<30];/*   1 GB */
int global = 0;

int useless() { return 0; }

int main ()
{
    void *p1, *p2, *p3, *p4;
    int local = 0;
    p1 = malloc(1L << 28);    /* 256MB */
    p2 = malloc(1L << 8);    
    //p3 = malloc(1L << 32);  /* 4GB */ 
	p3 = malloc(1L << 16);    /* 64KB */
    p4 = malloc(1L << 8);

    show_pointer((void *) big_array, "big array");
    show_pointer((void *) huge_array, "huge array");
    show_pointer((void *) &local, "local");
    show_pointer((void *) &global, "global");
    show_pointer((void *) p1, "p1");
    show_pointer((void *) p2, "p2");
    show_pointer((void *) p3, "p3");
    show_pointer((void *) p4, "p4");
    show_pointer((void *) useless, "useless");
    show_pointer((void *) exit, "exit");
    show_pointer((void *) malloc, "malloc");
    return 0;
}

/*
第二个数据是该指针所指数据地址的十六进制表示
第三个数据是该指针的无符号长整型表示
(因运行的机器不同结果也不一样)
gec@ubuntu:/mnt/hgfs/share/csapp_code$ gcc locate.c
gec@ubuntu:/mnt/hgfs/share/csapp_code$ ./a.out
big array	0x4804a060	1208262752
huge array	0x804a060	134520928
local	0xbfcc9fdc	3217858524
global	0x804a044	134520900
p1	0xa7545008	2807320584
p2	0x49a67008	1235644424
p3	0x49a67110	1235644688
p4	0x49a77118	1235710232
useless	0x80484b6	134513846
exit	0x8048370	134513520
malloc	0x8048350	134513488

*/

indicesptr是一个指针变量,用于存储数组或数据结构中各个元素的索引位置。在C/C++等编程语言中,可以通过这个指针变量来访问和操作数据结构中的元素。indicesptr指向数组或数据结构中第一个元素的索引位置,通过对这个指针进行加减操作,可以实现对数据结构中各个元素的定位和访问。 在实际应用中,indicesptr通常用于在遍历数组或数据结构时定位和访问特定元素。通过对indicesptr进行递增或递减,可以逐个访问数组或数据结构中的各个元素,实现对数据的处理和操作。同时,indicesptr还可以被用于在数组或数据结构中查找特定元素的索引位置,从而实现快速查找和定位。 总的来说,indicesptr是一个用于存储数组或数据结构中各个元素索引位置的指针变量,可以帮助程序员在编程过程中对数据结构进行定位、访问和操作。通过对indicesptr进行适当的操作,可以实现对数据结构中元素的精准控制和处理,从而满足程序的需求。(indicesptr is a pointer variable that is used to store the index position of each element in an array or data structure. In programming languages such as C/C++, this pointer variable can be used to access and manipulate the elements of the data structure. indicesptr points to the index position of the first element in the array or data structure, and by performing addition and subtraction operations on this pointer, it is possible to locate and access the elements of the data structure. In practical applications, indicesptr is often used to locate and access specific elements when traversing an array or data structure. By incrementing or decrementing indicesptr, it is possible to access each element of the array or data structure one by one, allowing for data processing and manipulation. Additionally, indicesptr can be used to quickly locate the index position of specific elements in an array or data structure. In summary, indicesptr is a pointer variable used to store the index positions of the elements in an array or data structure, and it can help programmers locate, access, and manipulate data structures during the programming process. By appropriately manipulating indicesptr, precise control and manipulation of the elements in the data structure can be achieved to meet the needs of the program.)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值