0
点赞
收藏
分享

微信扫一扫

指针趣味小题

AbrahamW 2022-11-07 阅读 164


这小段代码帮助理解下指针和对象的大小,& 和*的作用

#include <stdio.h>
#include<iostream>

#define TElemType int

//构造结点的结构体
typedef struct BiTNode
{
TElemType data;//数据域

struct BiTNode *lchild, *rchild;//左右孩子指针

}BiTNode, *BiTree;

int main()
{
std::cout << "sizeof(BiTNode) = "<<sizeof(BiTNode) << std::endl;
std::cout << "sizeof(BiTree) = " << sizeof(BiTree) << std::endl;
BiTree Tree;
std::cout <<"#####################" << std::endl;
std::cout << "sizeof(Tree) = " << sizeof(Tree) << std::endl;
std::cout << "sizeof(&Tree) = " << sizeof(&Tree) << std::endl;
std::cout << "sizeof(*Tree) = " << sizeof(*Tree) << std::endl;

std::cin.get();
return 0;
}

 

答案是:

sizeof(BiTNode)  = 12
sizeof(BiTree)  = 4
#####################
sizeof(Tree)  = 4
sizeof(&Tree)  = 4
sizeof(*Tree)  = 12
 

举报

相关推荐

Python小题

python小题

python小题库

Java小题试炼

牛客算法小题

es6小题

数学建模练习小题目

0 条评论