C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 
/*
    version: 1.0
    author: hellogiser
    blog: http://www.cnblogs.com/hellogiser
    date: 2014/6/3
*/
#include "stdafx.h"
#include <iostream>
using namespace std;

])
{
    // when a is passed to function,a will become a array pointer
    // like int (*p)[3], so sizeof(a)==4
    cout << sizeof(a) << endl; // 4
}

void test_2dim()
{
    // array pointer
};
    ];
    p = a;
    fun(a);

// test sizeof
    // for a
    cout << sizeof(a) << endl; // 24
) << endl; // 4  (24 in debug local watch)
) << endl; // 4  (24 in debug local watch)

cout << ]) << endl; // 12
]) << endl; // 12
)) << endl; // 12
)) << endl; // 12
]) << endl; // 4

// for p
    cout << sizeof(p) << endl; // 4
) << endl; // 4
) << endl; // 4

cout << ]) << endl; // 12
]) << endl; // 12
)) << endl; // 12
)) << endl; // 12
]) << endl; // 4

// pointer array
];
    ;
    ;
    r[] = &i;
    r[] = &j;
    cout << sizeof(r) << endl; // 8
}

void test_1dim()
{
    };
    int *p = a;
    int *p1 = (int *)&a;
    );

]; // array pointer
    b = &a;
    int *b1 = (int *)b;
    );

cout << "ok" << endl;
}

void test_string()
{
    char *str1 = "abcd";
    char str2[] = "1234";

cout << str1 << endl; // abcd
    cout << str2 << endl; // 1234
    cout << *str1 << endl; // a
    cout << *str2 << endl; // 1

//str1[0]='X'; // ERROR
] = 'Y'; // right
    cout << *str2 << endl; // Y
}

void funstr(char str[])
{
    printf("After transform:%d\n", sizeof(str));  //4
}

void test_array_as_param()
{
    char strs[] = "abcdefg";
    printf("Before transform:%d\n", sizeof(strs)); //8
    funstr(strs);
}

void test_a()
{
    // (int&)a treat a memory as a integer
.0f;
    cout << (int)a << endl;  // 1
    cout << (int &)a << endl; // 1065353216
    cout << boolalpha << ( (int)a == (int &)a ) << endl; // false

.0f;
    cout << (int)b << endl; // 0
    cout << (int &)b << endl; // 0
    cout << boolalpha << ( (int)b == (int &)b ) << endl; // true
}

TestPointer的更多相关文章

  1. typedef与#define的区别

    1.  typedef typedef故名思意就是类型定义的意思,但是它并不是定义一个新的类型而是给已有的类型起一个别名,在这一点上与引用的含义类似,引用是变量或对象的别名,而typedef定义的是类 ...

  2. JSPatch学习笔记

    本文参考JSPatch wiki :https://github.com/bang590/JSPatch/wiki 1.概念 JSPatch是一个轻量的JS引擎,能够使用JavaScript语言来调用 ...

  3. VC 宏与预处理使用方法总结

    目录(?) C/C++ 预定义宏^ C/C++ 预定义宏用途:诊断与调试输出^ CRT 和 C 标准库中的宏^ NULL 空指针^ limits.h 整数类型常量^ float.h 浮点类型常量^ m ...

  4. Go学习笔记01-语言

    1.1 变量 Go 是静态类型语言,不能在运行期改变变量类型.使用关键字 var 定义变量,自动初始化为零值.如果提供初始化值,可省略变量类型,由编译器自动推断. var x int var f fl ...

  5. Java程序员的Golang入门指南(上)

    Java程序员的Golang入门指南 1.序言 Golang作为一门出身名门望族的编程语言新星,像豆瓣的Redis平台Codis.类Evernote的云笔记leanote等. 1.1 为什么要学习 如 ...

  6. iOS中 动态热修补技术JSPatch 韩俊强的博客

    .1.4) JSPatch bridge Objective-C and JavaScript. You can call any Objective-C class and method in Ja ...

  7. C++哪些运算符重载能够重载?

    运算符重载是C++极为重要的语言特性之中的一个.本文将用代码实例回答--C++哪些运算符能够重载?怎样重载?实现运算符重载时须要注意哪些? 哪些运算符能够重载,哪些不可重载? C++98,C++0x, ...

  8. 雷林鹏分享:C# 不安全代码

    C# 不安全代码 当一个代码块使用 unsafe 修饰符标记时,C# 允许在函数中使用指针变量.不安全代码或非托管代码是指使用了指针变量的代码块. 指针变量 指针 是值为另一个变量的地址的变量,即,内 ...

  9. go基础语法-指针

    1.基础定义 golang的指针没有cpp等语言的指针复杂,具体表现在其不可用于运算.只有值传递 语法:var variableName *int = memoryAddr var a = 2 var ...

随机推荐

  1. Html-Css-iframe的使用

    iframe是作为在网页中嵌套网页的标签 <iframe src="homeIndex_init.html" width="100%" height=&q ...

  2. 『jQuery』.html(),.text()和.val()的概述及使用

    转自http://www.jb51.net/article/35867.htm 如何使用jQuery中的.html(),.text()和.val()三种方法,用于读取,修改元素的html结构,元素的文 ...

  3. python_元组

    元组 元组是用圆括号括起来的,其中的元素之间用逗号隔开.(都是英文半角) >>># 变量引用 str >>> s = "abc" >> ...

  4. USACO 3.2 kimbits DP

    自己YY了个DP:设f[n][l]为n位数中包含不超过l个1的总个数 f[n][l]=f[n-1][l]+f[n-1][l-1] 然后用_search()从高位向低位扫描即可,tmp记录当前已记下多少 ...

  5. TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133

    程序代码  class Person:      #constructor      def __init__(self,name,sex):           self.Name = name   ...

  6. java 文件读取大全

    1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile {     /**      * 以字节为单位读取文件,常用 ...

  7. Oracle DBA从小白到入职实战应用

    现如今Oracle依然是RDBMS的王者,在技术上和战略上,Oracle仍然一路高歌猛进,并且全面引领行业迈入了云时代,伴随着12cR2即将在2016年正式发布,学习Oracle之路依旧任重道远,目前 ...

  8. jQueryEasyUI DateBox的基本使用

    http://www.cnblogs.com/libingql/archive/2011/09/25/2189977.html 1.基本用法 代码: 1 2 3 4 5 6 7 8 9 10 11 1 ...

  9. CentOS 6.3 NFS的安装配置、启动及mount挂载方法

    一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS的安装配置: centos 5 : yum -y install ...

  10. OOA/OOD/OOP(了解)

    Object-Oriented Analysis:面向对象分析方法 是在一个系统的开发过程中进行了系统业务调查以后,按照面向对象的思想来分析问题.OOA与结构化分析有较大的区别.OOA所强调的是在系统 ...