Data Types – What is a Primitive Data Type?

data types

My understanding of a primitive datatype is that

It is a datatype provided by a language implicitly (Others are user defined classes)

So different languages have different sets of datatypes which are considered primitive for that particular language. Is that right?

And what is the difference between a "basic datatype" and "built-in datatype". Wikipedia says a primitive datatype is either of the two.

PS – Why is "string" type considered as a primitive type in SNOBOL4 and not in Java ?

Best Answer

It kind of depends on the language.

For example, in languages like C and C++, you have a number of built-in scalar types - int, float, double, char, etc. These are "primitive" in the sense that they cannot be decomposed into simpler components. From these basic types you can define new types - pointer types, array types, struct types, union types, etc.

Then you have a language like old-school Lisp, where everything is either an atom or a list. Again, by the above definition, an atom is "primitive" in the sense that it cannot be decomposed into something simpler.

Edit

As far as I'm concerned, the terms "primitive", "basic", and "built-in" are pretty much interchangeable. If you want to get really pedantic, though, you can distinguish between types that are "built-in" (those explicitly provided by the language definition) and types derived from the built-in types that are still "primitive" or "basic" in that they cannot be decomposed into simpler elements. C's typedef facility allows you to create new type names for existing types. Ada allows you to create new scalar types that have constraints on them. For example, you can derive a Latitude type from the built-in floating type, with the constraint that it can't take on values outside the range [-90.0, 90.0]. It's still a primitive or basic type in that it cannot be broken down into any simpler components, but since it's user-defined, it's not considered a "built-in" type.

Again, these concepts are a little fuzzy, and it really depends on context. For example, the notion of a "built-in" type is meaningless for a typeless language like BLISS.

Related Topic