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. codevs 1360 xth砍树 线段树不能再水的题了

    连标记都不用打.. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...

  2. Tomcat+eclipse JSP windows开发环境配置

    一.安装Java SE http://www.oracle.com/technetwork/java/javase/downloads/index.html ,配置JAVA_HOME环境变量 二.安装 ...

  3. c++重载运算符注意

    c++重载运算符的时候加&或不加: 如果加了&表示引用,说明用的都是同一块内存.如果不加,那么用的就是一份拷贝,即不同的内存. 一般连续操作的时候要加&. 可以重新定义一个对象 ...

  4. 细菌觅食算法-python实现

    BFOIndividual.py import numpy as np import ObjFunction class BFOIndividual: ''' individual of bateri ...

  5. codevs1003 电话连线

    题目描述 Description 一个国家有n个城市.若干个城市之间有电话线连接,现在要增加m条电话线(电话线当然是双向的了),使得任意两个城市之间都直接或间接经过其他城市有电话线连接,你的程序应该能 ...

  6. 在网络7层协议中,如果想使用UDP协议达到TCP协议的效果,可以在哪层做文章?(QQ 为什么采用 UDP 协议,而不采用 TCP 协议实现?)

    为了解决这题,可以具体看看下面这个讨论. 解灵运工程师 185 人赞同 某次架构师大会上那个58同城做即时通信的人说:原因是因为当时没有epoll这种可以支持成千上万tcp并发连接的技术,所以他们使用 ...

  7. css中的id和css的区别

    在样式表定义一个样式的时候,可以定义id也可以定义class. 1.在CSS文件里书写时,ID加前缀"#":CLASS用"." 2.id一个页面只可以使用一次: ...

  8. MyEclipse------制作通讯录

    addinfo.java public class addinfo extends HttpServlet { private String url="jdbc:mysql://localh ...

  9. PHP防止重复提交表单(helloweba网站经典实例)

    <?php session_start(); header("Content-Type:text/html;charset:utf8"); function set_toke ...

  10. Lua函数之一

    LUA函数之一 函数声明: function foo(arguments) statements end 1.函数调用 调用函数的时候,如果参数列表为空,必须使用()表明是函数调用,例如: os.da ...