C语言中的对象 [英] Objects in C language

查看:85
本文介绍了C语言中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我浏览一些 C 的教程/笔记时,我还是会遇到对象"这个词.我一直想知道对象与过程语言有什么关系.深入一点我可以理解,占用一块内存的东西在c中被称为对象".

Wheneven I go through some tutorials/notes for C, I quite come across the term "objects". I was always wondering what does the object got to do with the procedural language. Going a bit deep I could understand that something occupying a piece of memory is termed as an "object" in c.

我的问题是我的理解是正确的还是我遗漏了什么.谢谢!

My question is whether my understanding is correct or is there something I am missing. Thanks!

推荐答案

来自 C99 标准草案:

3.14
对象
执行环境中的数据存储区域,其中的内容可以表示值

3.14
object
region of data storage in the execution environment, the contents of which can represent values

所以,你基本上是对的.

So, you're basically right.

注意事项:

  • 一个对象可以有一个名字:int object = 42;
  • 一个对象可以是一个更大对象的一部分:struct tm x;/* (x) 和 (x.tm_year) 是对象 */
  • 一个对象可以动态分配:int *arr = malloc(42);if (arr)/* arr[4] 是一个对象 */;

这篇关于C语言中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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