pointer p, addr of pointer p, value of *p

void pointer(int *p)
{
  int a = 11;
  printf("\nthe p is %p , addr is %p, *p is %d",p , &p, *p);
  *p =11;
  printf("\nthe p is %p , addr is %p, *p is %d",p , &p, *p);
  p = &a;
  printf("\nthe p is %p , addr is %p, *p is %d",p , &p, *p);
}

int main()
{
 int b =22;
 int *p = &b;

 printf("the p is %p , addr is %p, *p is %d",p , &p, *p);
 pointer(p);
 printf("\nthe p is %p , addr is %p, *p is %d\n",p , &p, *p);
}

运行结果:

the p is 00A0FEE4 , addr is 00A0FEDC, *p is 22
the p is 00A0FEE4 , addr is 00A0FEE0, *p is 22
the p is 00A0FEE4 , addr is 00A0FEE0, *p is 11
the p is 00A0FEE8 , addr is 00A0FEE0, *p is 11
the p is 00A0FEE4 , addr is 00A0FEDC, *p is 11

时间: 2024-10-13 12:09:49

pointer p, addr of pointer p, value of *p的相关文章

使用unsafe.Pointer将结构体转为[]byte

package main import ( "fmt" "unsafe" ) type TestStructTobytes struct { data int64 s int8 } type SliceMock struct { addr uintptr len int cap int } func main() { var testStruct = &TestStructTobytes{100, 'a'} Len := unsafe.Sizeof(*tes

智能指针(smart pointer)(2):unique_ptr

Unique pointer: Manages the storage of a pointer, providing a limited garbage-collection facility, with little to no overhead over built-in pointers (depending on the deleter used). These objects have the ability of taking ownership of a pointer: onc

Go语言阅读小笔记,来自知呼达达关于unsafe.Pointer的分享.

第一式 - 获得Slice和String的内存数据 func stringPointer(s string) unsafe.Pointer { p := (*reflect.StringHeader)(unsafe.Pointer(&s)) return unsafe.Pointer(p.Data) } func bytePointer(b []byte) unsafe.Pointer { p := (*reflect.SliceHeader)(unsafe.Pointer(&b)) re

Leetcode 138. Copy List with random pointer

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 思路:deep copy的意思就是克隆.扫两遍原来的list,第一遍copy node和next.然后再扫第二遍,这是如果pointer.random非空,我们就可以在co

smart pointer

smart pointer是一种abstract data type,它能够模仿指针的行为,并且额外提供了一系列诸如自动内存管理.边界检查等特性,这些特性是为了在保证效率的基础上减少由于对指针的不正常使用而带来的bug.smart pointer能够自动进行object的销毁:当某个object的最后一个拥有者被destroy的时候(如局部变量离开了作用域),由smart pointer管理的object会被自动销毁.smart pointer是被声明在stack中的 在C++中,smart p

Tagged Pointer

前言 在2013年9月,苹果推出了iPhone5s,与此同时,iPhone5s配备了首个采用64位架构的A7双核处理器,为了节省内存和提高执行效率,苹果提出了Tagged Pointer的概念.对于64位程序,引入Tagged Pointer后,相关逻辑能减少一半的内存占用,以及3倍的访问速度提升,100倍的创建.销毁速度提升.本文从Tagged Pointer试图解决的问题入手,带领读者理解Tagged Pointer的实现细节和优势,最后指出了使用时的注意事项. 问题 我们先看看原有的对象为

differences between null pointer and void pointer.

These are two different concepts, you cannot compare them. What the difference between the skunk and the moonlight? Null pointer is a special reserved value of a pointer. A pointer of any type has such a reserved value. Formally, each specific pointe

[CareerCup] 13.8 Smart Pointer 智能指针

13.8 Write a smart pointer class. A smart pointer is a data type, usually implemented with templates, that simulates a pointer while also providing automatic garbage collection. It automatically counts the number of references to a SmartPointer<T*>

《C和指针(Pointer on c)》 学习笔记(转自:http://dsqiu.iteye.com/blog/1687944)

首先本文是对参考中三个连接的博客进行的整理,非常感谢三位博主的努力,每次都感叹网友的力量实在太强大了…… 第一章 快速上手 1.  在C语言中用/*和*/来注释掉这段代码,这个实际上并不是十分的安全,要从逻辑上删除一段C代码,最好的办法是使用#if指令: #if 0 Statement #endif 2.  其他语言中,无返回值的函数称为过程(procedure). 3.  数组做参数的时候是以引用(reference)的方式传递的,即地址传递.而标量和常量都是传值调用,被调用的函数无法修改调用