Creating an Array: Difference between revisions
Content added Content deleted
(→AWK: Delete.) |
(→C: Delete.) |
||
Line 156: | Line 156: | ||
FreeBASIC has an option to initialize array while declaring it. |
FreeBASIC has an option to initialize array while declaring it. |
||
<lang freebasic> Dim myArray(1 To 2, 1 To 5) As Integer => {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}} </lang> |
<lang freebasic> Dim myArray(1 To 2, 1 To 5) As Integer => {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}} </lang> |
||
==[[C]]== |
|||
Dynamic |
|||
<lang c> #include <stdlib.h> /* for malloc */ |
|||
#include <string.h> /* for memset */ |
|||
int n = 10 * sizeof(int); |
|||
int *myArray = (int*)malloc(n); |
|||
if(myArray != NULL) |
|||
{ |
|||
memset(myArray, 0, n); |
|||
myArray[0] = 1; |
|||
myArray[1] = 2; |
|||
free(myArray); |
|||
myArray = NULL; |
|||
}</lang> |
|||
Static |
|||
<lang c> int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */</lang> |
|||
==[[C++]]== |
==[[C++]]== |