mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
Add skeleton for arrays in IR
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
int sum(int len, int p[2][3]) {
|
||||
return 0;
|
||||
int sum(int len, int *p) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
result += p[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[2][3];
|
||||
int a[5];
|
||||
int len = 5;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return sum(len, a) == 10;
|
||||
}
|
||||
|
||||
16
examples/array2.c
Normal file
16
examples/array2.c
Normal file
@@ -0,0 +1,16 @@
|
||||
void init(int row, int col, int a[4][5]) {
|
||||
for (int i = 0; i < row; i++) {
|
||||
for (int j = 0; j < col; j++) {
|
||||
a[i][j] = i * j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[4][5];
|
||||
int row = 4, col = 5;
|
||||
|
||||
init(row, col, a);
|
||||
|
||||
return a[2][3] == 6;
|
||||
}
|
||||
13
examples/array3.c
Normal file
13
examples/array3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int* foo(int a[10]){
|
||||
return a;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[10];
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
(foo(a))[i] = i;
|
||||
}
|
||||
|
||||
return a[5] == 5;
|
||||
}
|
||||
Reference in New Issue
Block a user