Identifying data type of a value in memory in C?

前端 未结 5 1275
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 11:21

How does a program/application know that the data in a memory address is of a certain data type.

For instance, suppose there is int a; and suppose variable

5条回答
  •  -上瘾入骨i
    2021-01-21 11:37

    This information is not stored. For example, you could do things like

    int i=15;
    char *p=(char*)&i;
    char c=*p; //Now, c contain the first byte of 15, which may be 15 or 0
    

    But don't do this unless you really know what do you do. Do stuff like this uncarefully is a common way to errors.

提交回复
热议问题