by Animats · 6y ago · 0 comments
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
>>> n = 10
>>> allocation = [42] * n
>>> allocation
[42, 42, 42, 42, 42, 42, 42, 42, 42, 42]
That's what "*" does on lists in Python. The idea is that "abc" + def" is "abcdef", and then they overgeneralized. $ cat test.c
#include <stdio.h>
#include <string.h>
int main() {
int n = 10;
int allocation[n];
memset(allocation, 42, sizeof(allocation));
for(int i = 0; i < n; i ++)
printf("%d\n", allocation[i]);
}
$ gcc test.c
$ ./a.out
707406378
707406378
707406378
707406378
707406378
707406378
707406378
707406378
707406378
707406378