C:
int myArray[4]; // Declares an array of 4 integers
JavaScript:
let myArray = []; // Declares an empty array
C:
myArray[0] = 10; // Sets the first element to 10
int firstElement = myArray[0]; // Gets the first element
JavaScript:
myArray[0] = 10; // Sets the first element to 10
let firstElement = myArray[0]; // Gets the first element
C:
int myArray[4] = {42, 39, 16, 7}; // Initializes the array with specific values
JavaScript:
let myArray = [42, 39, 16, 7]; // Initializes the array with specific values
C:
int *newArray = malloc(newSize * sizeof(int));
memcpy(newArray, oldArray, oldSize * sizeof(int));
free(oldArray);
oldArray = newArray;
JavaScript:
myArray.push(5); // Adds an element to the end of the array
C:
int myArray[4]; // All elements must be integers
JavaScript:
let myArray = [42, 'hello', true]; // Elements can be of different types
C:
int x = myArray[5]; // Undefined behavior if myArray has less than 6 elements
JavaScript:
undefined
without throwing an error.let x = myArray[5]; // Returns undefined if myArray has less than 6 elements
C:
int *myArray = malloc(10 * sizeof(int)); // Allocate memory for 10 integers
free(myArray); // Free the allocated memory