You are on page 1of 7

m

e r as
co
eH w
CS 315

o.
rs eHomework Assignment 1
ou urc
Arrays in C, Javascript, Python, Perl and PHP
o
aC s
v i y re
ed d
ar stu
sh is

Zafer Tan ÇANKIRI


Th

#21602169
CS 315-1

https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
C:
1. What types are legal for subscripts?

• Only int type is legal for subscripts in C.

2. Are subscripting expressions in element references range checked?

• No. There is no range check mechanism for subscripting expressions in C. An array


with an out-of-ranged index returns garbage value in C.

3. When are subscript ranges bound?

• Static Arrays : Load Time

m
• Dynamic Arrays : Runtime

e r as
co
4. When does allocation take place?

eH w
o.
• Static Arrays : Load Time
rs e
• Dynamic Arrays : Runtime
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?
o

• Both ragged and rectangular multidimensional arrays are allowed. We can use
aC s

pointer array for this purpose or we can define our arrays as multidimensional
v i y re

already.

6. What is the maximum number of subscripts?


ed d

• In theory, C can take any numbers of subscripts which is about the level of
ar stu

multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory or the compiler specification.
sh is

7. Can array objects be initialized?


Th

• Yes. Array objects can be initialized.

8. Are any kind of slices supported?

• No. There is no array slicing mechanism in C.

2
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Javascript:
1. What types are legal for subscripts?

• Everything syntactical correct is legal for subscripts in Javascript. (All Types)

2. Are subscripting expressions in element references range checked?

• No. There is no range check mechanism in Javascript. The script continues to run
without any error, but the array returns ‘undefined’ as the result for out-of-ranged
subscript.

3. When are subscript ranges bound?

m
• Since Javascript is an interpreted language, the range binding takes place in runtime.

e r as
co
4. When does allocation take place?

eH w
o.
• Since Javascript is an interpreted language, the allocation takes place in runtime.
rs e
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?

• Both ragged and rectangular multidimensional arrays are allowed.


o
aC s

6. What is the maximum number of subscripts?


v i y re

• In theory, Javascript can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
ed d
ar stu

7. Can array objects be initialized?

• Yes. Array objects can be initialized.


sh is

8. Are any kind of slices supported?


Th

• Yes. Arrays have slice function which can be used to slice arrays in Javascript.

3
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Python:
1. What types are legal for subscripts?

• There is no array type in python. However, list objects can be used as arrays, and
for the list objects only int type is legal for subscripts in Python. Also, associative
arrays can be also considered as arrays. In Python, there is the dictionary data
structure and it can take immutable data types as key for its subscripts. Therefore, it
can be said that float, string, even tuple can be used for subscript beside int.

2. Are subscripting expressions in element references range checked?

• Yes. There is a range check mechanism which takes place in runtime in Python. On
the other hand, Python accepts out-of-bounded operations while slicing, but it

m
returns only the elements inside the bounds.

e r as
co
3. When are subscript ranges bound?

eH w

o.
Since Python is an interpreted language, the range binding takes place in runtime.
rs e
ou urc
4. When does allocation take place?

• Since Python is an interpreted language, the allocation takes place in runtime.


o
aC s

5. Are ragged or rectangular multidimensional arrays allowed, or both?


v i y re

• Both ragged and rectangular multidimensional arrays are allowed.

6. What is the maximum number of subscripts?


ed d
ar stu

• In theory, Python can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
sh is

7. Can array objects be initialized?


Th

• Yes. There is no array type in python. However, list objects can be used as arrays,
and list objects can be initialized.

8. Are any kind of slices supported?

• Yes. Python supports slice operations for list objects which can be used as arrays.

4
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Perl:
1. What types are legal for subscripts?

• Only int type is legal for subscripts in Perl. Also, associative arrays can be also
considered as arrays, and Perl allows us to use string type for keys.

2. Are subscripting expressions in element references range checked?

• No. There is no range check mechanism in Perl. The script continues to run without
any error, but the array returns nothing as the result for out-of-ranged subscript.

3. When are subscript ranges bound?

m
• Since Perl is an interpreted language, the range binding takes place in runtime.

e r as
co
4. When does allocation take place?

eH w
o.
• Since Perl is an interpreted language, the range binding takes place in runtime.
rs e
ou urc
5. Are ragged or rectangular multidimensional arrays allowed, or both?

• Both ragged and rectangular multidimensional arrays are allowed.


o
aC s

6. What is the maximum number of subscripts?


v i y re

• In theory, Perl can take any numbers of subscripts which is about the level of
multidimension of the array. On the other hand, there is a limitation about this and
it is the limit of the memory.
ed d
ar stu

7. Can array objects be initialized?

• Yes. Array objects can be initialized.


sh is

8. Are any kind of slices supported?


Th

• Yes. Arrays can be sliced with [a..b] operator in Perl.

5
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
PHP:
1. What types are legal for subscripts?

• Since all arrays in PHP are maps, all legal types (except Arrays and Objects) are
accepted for subscripts. They all hashed into long type key values which are used in
map to hold the values.

2. Are subscripting expressions in element references range checked?

• Yes. There is a range check mechanism in PHP. If the subscript is a key and the key
does not exist, then PHP gives out of bound error. If the subscript is an integer and
the index is out of the range of array, then PHP gives out of range error.

m
3. When are subscript ranges bound?

e r as
co
• Since it is an interpreted language, range binding in PHP takes place in runtime.

eH w
o.
4. When does allocation take place?
rs e
ou urc
• Since it is an interpreted language, allocation in PHP takes place in runtime.

5. Are ragged or rectangular multidimensional arrays allowed, or both?


o
aC s

• Both ragged and rectangular multidimensional arrays are allowed.


v i y re

6. What is the maximum number of subscripts?

• In theory, PHP can take any numbers of subscripts which is about the level of
ed d

multidimension of the array. On the other hand, there is a limitation about this and
ar stu

it is the limit of the memory.

7. Can array objects be initialized?


sh is

• Yes. Array objects can be initialized.


Th

8. Are any kind of slices supported?

• There is a function called array_slice which slices arrays in PHP.

6
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/
Zafer Tan ÇANKIRI
#21602169
CS 315-1
Discussion About Language Preference:
I prefer Python for array operations among these five languages. Array operations are mostly
used for mathematical and statistical purposes, and from my view, Python is the most suitable
one. It does not have array structures but it has lists which can be used as arrays, and the list
objects have lots of different operations for the manipulation of the data they store. Also, Python
has NumPy beside List, and it is also another powerful tool for array operations.

m
e r as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th

7
https://www.coursehero.com/file/38612979/cankiri-zafer-tan-reportpdf/

Powered by TCPDF (www.tcpdf.org)

You might also like