Computer Science, asked by deremahendra, 1 year ago

What do you understand by primitive and non primitive datatypes?Give an example of each.

Answers

Answered by aditya1022
0
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.
Answered by Anonymous
1

Hi

To understand these terms you have to understand how they get stored and how they get fetched from memory.

I assume that this question is related to JavaScript because you haven't mentioned programming language.

So first of all JavaScript is dynamic typed language, means you don't have to tell the engine which data type you want, engine will look at value and automatically assume the data type.

What is primitive type?

A type of data that represents a single value. (anything which is not an object is primitive)

there are six primitive types in JavaScript

1. undefined

2. null

3. boolean

4. number (float, double everything which is numeric is number in JavaScript)

5. string

6. symbol (new datatype in es6)

What is non primitive type?

anything which is not a single value, actually object only.



Similar questions