Scalar vs. primitive data type - are they the same thing?

后端 未结 7 529
深忆病人
深忆病人 2020-12-07 07:45

In various articles I have read, there are sometimes references to primitive data types and sometimes there are references to scalars.

My understanding of each is th

相关标签:
7条回答
  • 2020-12-07 08:18

    I like Scott Langeberg's answer because it is concise and backed by authoritative links. I would up-vote Scott's answer if I could.

    I suppose that "primitive" data type could be considered primary data type so that secondary data types are derived from primary data types. The derivation is through combining, such as a C++ struct. A struct can be used to combine data types (such as and int and a char) to get a secondary data type. The struct-defined data type is always a secondary data type. Primary data types are not derived from anything, rather they are a given in the programming language.

    I have a parallel to primitive being the nomenclature meaning primary. That parallel is "regular expression". I think the nomenclature "regular" can be understood as "regulating". Thus you have an expression that regulates the search.

    Scalar etymology (http://www.etymonline.com/index.php?allowed_in_frame=0&search=scalar&searchmode=none) means ladder-like. I think the way this relates to programming is that a ladder has only one dimension: How many rungs from the end of the ladder. A scalar data type has only one dimension, thus represented by a single value.

    I think in usage, primitive and scalar are interchangeable. Is there any example of a primitive that is not scalar, or of a scalar that is not primitive?

    Although interchangeable, primitive refers to the data-type being a basic building block of other data types, and a primitive is not composed of other data types.

    Scalar refers to its having a single value. Scalar contrasts with the mathematical vector. A vector is not represented by a single value because (using one kind of vector as an example) one value is needed to represent the vector's direction and another value needed to represent the vector's magnitude.

    Reference links: http://whatis.techtarget.com/definition/primitive http://en.wikipedia.org/wiki/Primitive_data_type

    0 讨论(0)
提交回复
热议问题