为什么指针声明需要数据类型? [英] Why data type is needed in pointer declaration?

查看:118
本文介绍了为什么指针声明需要数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解数据类型,同时声明一个变量,我们需要声明它的数据类型,它告诉编译器保留在相应的存储字节数。

As far as I know about Data type, while declaring a variable, we need to declare its data type, which tells the compiler to reserve the number of bytes in the memory accordingly.

但在情况下的指针,我们知道它们的大小总是 2字节(在Turbo编译)总是不管变量的数据类型它指向。

But in case of pointers, we know that their size is always of 2 bytes (in Turbo Compiler) always irrespective of the data type of the variable it is pointing.

我的问题是,如果在指针总是 2字节,那么什么是提在数据类型的必要性,同时宣布他们吗?还是我关于指针的理解是错误的?

My question is, if the pointers always take 2 bytes, then what is the need of mentioning the data type while declaring them? OR My understanding about pointers is wrong?

推荐答案

解引用指针时,所以它知道它应该多少数据读出需要的数据类型。例如取消引用字符指针应该读它指向ADRESS下一个字节,而一个int指针应读2个字节。

The Data type is needed when dereferencing the pointer so it knows how much data it should read. For example dereferencing a char pointer should read the next byte from the adress it is pointing to while an int pointer should read 2 bytes.

这篇关于为什么指针声明需要数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆