# 初始化

## 例子碼

C
```   /* variables */
int a = 2;
int b;
b = 20;
char string1 = 'a';
char string2 = 'f';

/* arrays and matrices */
float mark[5] = {19, 10, 8, 17, 9};
int markagain[3][4] = {
{0, 1, 2, 3} ,   /*  initializers for row indexed by 0 */
{4, 5, 6, 7} ,   /*  initializers for row indexed by 1 */
{8, 9, 10, 11}   /*  initializers for row indexed by 2 */
};

/* structs */
struct point {int x; int y;};
struct point p = {1, 3};
```
C++
```  // variables
int a, b;
int result = 10;
a = 5;
b = 2;

// arrays and matrices
int i[] = { 10, 20, 30 };
int j [3][4] = {
{0, 1, 2, 3} ,   //  initializers for row indexed by 0
{4, 5, 6, 7} ,   //  initializers for row indexed by 1
{8, 9, 10, 11}   //  initializers for row indexed by 2
};

// structs
struct point {int x; int y;};
struct point p = {1, 3};
```
Python
```  # variables
result = 10
a = 5
b = 2

# arrays and matrices
i = [1, 2, 3]
j = [[0 for x in range(5)] for y in range(5)] # a 5 x 5 matrix, all elements being 0.

# structs
class stru:
def __init__(self):
self.x = 0
self.y = 0
s = stru()
s.x = 10
```
MATLAB
```  % variables
result = 10;
a = 5;
b = 2;

% arrays and matrices
i = zeros(5,1); # a 5-item array, all elements being 0.
j = zeros(5,5); # a 5 x 5 matrix, all elements being 0.

% structs
s.x = 1;
s.y = {'A','B','C'};
```
Processing
```  // variables
int a = 100;
int b = 100;

// arrays and matrices
int[] i = new int[3];
int[][] j = {  {0, 1, 2, 3},
{3, 2, 1, 0},
{3, 5, 6, 1},
{3, 8, 3, 4}  };
```

## 參考

• A.K. Hartmann, Practical Guide to Computer Simulations, Singapore: World Scientific (2009).

## 引咗

1. Boehm, Hans-J. (2002). Destructors, Finalizers, and Synchronization. POPL.
2. C++ FAQs, by Cline, Lomow, and Girou, Addison-Wesley, 1999.