Creating an Array: Difference between revisions

(→‎{{header|BASIC}}: Dimension given is the upper bound.)
Line 831:
 
The [http://docs.python.org/library/ctypes.html#arrays ctypes module] can construct specialised arrays for interfacing with external C functions. The [http://docs.python.org/library/struct.html struct module] allows a string of characters to be interpreted as an array of values of C types such as 32 bit ints, float, etc.
 
=={{header|R}}==
<lang R>a <- vector("numeric", 10) # a is a vector (array) of 10 numbers
b <- vector("logical", 10) # b is an array of logical (boolean) values
s <- vector("character", 10) # s is an array of strings (characters)</lang>
 
Indexes start from 1
<lang R>a[1] <- 100
print(a[1]) # [1] 100</lang>
 
Let's initialize an array with some values
<lang R>a[1:3] <- c(1,2,3)
print(a) # [1] 1 2 3 0 0 0 0 0 0 0
# but this creates a brand new vector made of 3 elements:
a <- c(1,2,3)
# and the following fills b of TRUE FALSE, repeating them
b[] <- c(TRUE, FALSE)
print(b) # [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE</lang>
 
 
=={{header|Raven}}==