什么是 C 中的标量变量? [英] What is a Scalar Variable in C?

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

问题描述

我正在阅读 Kenneth Reek 所著的Pointers on C"并看到了这一行:

I was reading 'Pointers on C' by Kenneth Reek and saw this line:

结构变量是标量,因此您可以使用它执行与其他标量相同的操作.

A  structure  variable  is  a  scalar,  so  you  can  perform  the  same  kinds  of operations  with  it  that  you  can  with  other  scalars.

那是什么意思?

我在 SO 上发现了一个类似的问题,但它与其他一些语言(我猜是 SQL)有关

I found a similar question on SO but it was related to some other language (I guess SQL)

谢谢.

推荐答案

C11 标准的第 6.2.5 节解释:

Section 6.2.5 of the C11 standard explains:

算术类型和指针类型统称为标量类型.数组和结构类型统称为聚合类型.

Arithmetic types and pointer types are collectively called scalar types. Array and structure types are collectively called aggregate types.

继续贯穿整个标准,您会发现哪些操作和赋值可用于标量和聚合类型.

Continuing throughout the standard you find what operations and assignments are available for scalar and aggregate types.

您的声明:

结构变量是标量,因此您可以执行与其他操作相同的操作标量.

A structure variable is a scalar, so you can perform the same kinds of operations with it that you can with other scalars.

与 C 标准直接矛盾,因为结构是聚合类型而不是标量.也就是说,在有限的情况下,结构确实具有与标量相同的属性.例如,您可以分配两个相同类型的结构,并且复制构造函数在两个结构之间提供浅拷贝(分配).还有其他情况,但请注意它们是例外而不是规则.

Directly contradicts with the C-standard as structures are aggregate types not scalar. That said, there are limited cases where structures do possess the same properties as scalars. For example, you can assign two of the same type structures and the copy-constructor provides a shallow copy (assignment) between the two structs. There are other circumstances as well, but note they are the exception and not the rule.

我怀疑该声明是针对可以将 struct 视为该特定操作的标量的情况之一做出的.不知道在讨论什么操作,我不能进一步说.

I suspect the statement is made regarding one of those circumstances where a struct can be treated as a scalar for that particular operation. Without knowing what operation is being discussed, I cannot say further.

这篇关于什么是 C 中的标量变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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