Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
13. what is type casting?
Ans: (asting represents a re;uest by the programmer to do an e#plicit type
conversion. 'n standard ( programming, casts are done via the () operator, with
the name of the type to cast to inside. Aor e#ample:
int nBalue1 C 1:4
int nBalue& C -4
Doat fBalue C (Doat)nBalue1 = nBalue&4
'n the above program, we use a Doat cast to tell the compiler to promote nBalue1
to a Doating point value. 5ecause nBalue1 is a Doating point value, nBalue& will
then be promoted to a Doating point value as well, and the division will be done
using Doating point division instead of integer divisionE
Why "he Array 'nde# 6hould 6tart Arom :?
Ans : 'n (, the name of an array is essentially a pointer, a reference to a memory
location, and so the e#pression array1n2 refers to a memory location n%elements
away from the starting element. "his means that the inde# is used as an o+set.
"he ?rst element of the array is e#actly contained in the memory location that
array refers (: elements away), so it should be denoted as array1:2. <ost
programming languages have been designed this way, so inde#ing from : is
pretty much inherent to the language.