In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving .
- Char A =ASCI value 127
- Int value 127
Binary is same then how computer understand this value..
In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving .
Binary is same then how computer understand this value..
It's all about context. They do actually not differ at all.
Lets assume we have two arrays. One contains the characters
foo = 'test'
another contains the following decimal values:
bar = [116, 101, 115, 116, 0]
Now say we have a function sum
that takes an array and sums its values. We call it with
sum(bar)
and the result is 448.
Now call it with
sum(foo)
and the result is 448 again. Surprise.
Ok, another function culled uppercase
which takes a string and returns it in upper case.
uppercase(foo)
returns 'TEST', but
uppercase(bar)
will just do the same!
This ignores any type checks your programming language may do. So if you have defined one variable as string and the other as array of integers your compiler may complain and your code not compile. But this is a kind of 'meta' feature that makes assumptions about your data that have nothing to do with the much simpler representation on the memory level where all things are just numbers.
But if you have a language where you can turn that off or ignore it or use assembler directly on a machine level where your 'variables' are only addresses in memory the above examples show the underlying behaviour.
Actually I added the trailing zero in my example only because certain languages would require a string to be terminated that way. So even this is not exactly mandatory but only exists because a certain context demands it.
But that whole thing is only true for simple string representations. The C language expects the string to terminate with zero, Pascal would expect it to have the length as its first element: [4, 116, 101, 115, 116]
Object oriented languages would possibly store them even more complicated. Non ASCII strings like UTF8, Unicode etc would be rather complex. (though the data part itself at some point again just an array of numbers that in theory can be handled whatever way you like)