-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b48ba93
commit 16c8512
Showing
32 changed files
with
271 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
int zippo[4][2] = | ||
{ | ||
{2, 4}, {6, 8}, {1, 3}, {5, 7} | ||
}; | ||
|
||
printf (" zippo = %p, zippo + 1 = %p\n", zippo, zippo + 1); | ||
printf ("zippo[0] = %p, zippo[0] + 1 = %p\n", zippo[0], zippo[0] +1); | ||
printf (" *zippo = %p, *zippo + 1 = %p\n", *zippo, *zippo + 1); | ||
printf ("zippo[0][0] = %d\n", zippo[0][0]); | ||
printf ("*zippo[0] = %d\n", *zippo[0]); | ||
printf ("**zippo = %d\n", **zippo); | ||
printf ("zippo[2][1] = %d\n", zippo[2][1]); | ||
printf ("*(*zippo + 2) + 1 = %d\n", *(*(zippo + 2) + 1)); | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
int zippo[4][2] = {{2, 4}, {6, 8}, {1, 3}, {5, 7}}; | ||
int (*pz)[2]; | ||
pz = zippo; | ||
|
||
printf ("pz = %p, pz + 1 = %p\n\n", pz, pz + 1); | ||
printf ("pz[0] = %p, pz[0] + 1 = %p\n\n", pz[0], pz[0] + 1); | ||
printf ("*pz = %p, *pz + 1 = %p\n\n", *pz, *pz + 1); | ||
printf ("pz[0][0] = %d\n", pz[0][0]); | ||
printf ("*pz[0] = %d\n", *pz[0]); | ||
printf ("**pz = %d\n", **pz); | ||
printf ("pz[2][1] = %d\n", pz[2][1]); | ||
printf ("*(*(pz + 2) + 1) = %d\n", *(*(pz + 2) + 1)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
#include "10.17_18.h" | ||
int main (void) | ||
{ | ||
int junk[ROWS][COLS] = | ||
{ | ||
{2, 4, 6, 8}, | ||
{3, 5, 7, 9}, | ||
{12, 10, 8, 6} | ||
}; | ||
|
||
sum_rows (junk, ROWS); | ||
sum_cols (junk, ROWS); | ||
printf ("Sum of all elements = %d\n", sum2d (junk, ROWS)); | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#define ROWS 3 | ||
#define COLS 4 | ||
void sum_rows (int ar[][COLS], int rows); | ||
void sum_cols (int ar[][COLS], int rows); | ||
int sum2d (int (*ar)[COLS], int rows); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <stdio.h> | ||
#include "10.17_18.h" | ||
void sum_rows (int ar[][COLS], int rows) | ||
{ | ||
int r; | ||
int c; | ||
int tot; | ||
|
||
for (r = 0; r < rows; r ++) | ||
{ | ||
tot = 0; | ||
for (c = 0; c < COLS; c ++) | ||
{ | ||
tot += ar[r][c]; | ||
} | ||
printf ("row %d: sum = %d\n", r, tot); | ||
} | ||
} | ||
void sum_cols (int ar[][COLS], int rows) | ||
{ | ||
int r; | ||
int c; | ||
int tot; | ||
|
||
for (c = 0; c < COLS; c ++) | ||
{ | ||
tot = 0; | ||
for (r = 0; r < rows; r ++) | ||
{ | ||
tot += ar[r][c]; | ||
} | ||
printf ("col %d: sum = %d\n", c, tot); | ||
} | ||
} | ||
int sum2d (int ar[][COLS], int rows) | ||
{ | ||
int r; | ||
int c; | ||
int tot = 0; | ||
|
||
for (r = 0; r < rows; r ++) | ||
{ | ||
for (c = 0; c < COLS; c ++) | ||
{ | ||
tot += ar[r][c]; | ||
} | ||
} | ||
|
||
return tot; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include "10.19_20.h" | ||
int main (void) | ||
{ | ||
int i, j; | ||
int rs = 3; | ||
int cs = 10; | ||
|
||
int junk[ROWS][COLS] = | ||
{ | ||
{2, 4, 6, 8}, | ||
{3, 5, 7, 9}, | ||
{12, 10, 8, 6} | ||
}; | ||
int morejunk[ROWS - 1][COLS + 2] = | ||
{ | ||
{20, 30, 40, 50, 60, 70}, | ||
{5, 6, 7, 8, 9, 10} | ||
}; | ||
int varr[rs][cs]; | ||
|
||
for (i = 0; i < rs; i ++) | ||
{ | ||
for (j = 0; j < cs; j ++) | ||
{ | ||
varr[i][j] = i * j + j; | ||
} | ||
} | ||
printf ("3 * 5 array\n"); | ||
printf ("Sum or all elements = %d\n", sum2d (ROWS, COLS, junk)); | ||
printf ("2 * 6 array\n"); | ||
printf ("Sum of all elements = %d\n", sum2d (ROWS -1, COLS + 2, morejunk)); | ||
printf ("3 * 10 VLA\n"); | ||
printf ("Sum of all elements = %d\n", sum2d (rs, cs, varr)); | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#define ROWS 3 | ||
#define COLS 4 | ||
int sum2d (int rows, int cols, int ar[rows][cols]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include "10.19_20.h" | ||
int sum2d (int rows, int cols, int ar[rows][cols]) | ||
{ | ||
int r; | ||
int c; | ||
int tot = 0; | ||
|
||
for (r = 0; r < rows; r ++) | ||
{ | ||
for (c = 0; c < cols; c ++) | ||
{ | ||
tot += ar[r][c]; | ||
} | ||
} | ||
|
||
return tot; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include "10.21_22.h" | ||
int main (void) | ||
{ | ||
int total1, total2, total3; | ||
int * pt1; | ||
int(*pt2)[COLS]; | ||
|
||
pt1 = (int[2]){10, 20}; | ||
pt2 = (int[2][COLS]){{1, 2, 3, -9}, {4, 5, 6, -8}}; | ||
total1 = sum (pt1, 2); | ||
total2 = sum2d(pt2, 2); | ||
total3 = sum ((int []){4, 4, 4, 5, 5, 5}, 6); | ||
printf ("total1 = %d\n", total1); | ||
printf ("total2 = %d\n", total2); | ||
printf ("total3 = %d\n", total3); | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define COLS 4 | ||
int sum2d (const int ar[][COLS], int rows); | ||
int sum (const int ar[], int n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include "10.21_22.h" | ||
int sum (const int ar[], int n) | ||
{ | ||
int i; | ||
int total = 0; | ||
|
||
for (i = 0; i < n; i ++) | ||
{ | ||
total += ar[i]; | ||
} | ||
|
||
return total; | ||
} | ||
int sum2d (const int ar[][COLS], int rows) | ||
{ | ||
int r; | ||
int c; | ||
int tot = 0; | ||
|
||
for (r = 0; r < rows; r ++) | ||
{ | ||
for (c = 0; c < COLS; c ++) | ||
{ | ||
tot += ar[r][c]; | ||
} | ||
} | ||
|
||
return tot; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
int ref[] = {8, 4, 0, 2}; | ||
int *ptr; | ||
int index; | ||
|
||
printf ("%d\n", *++ref); | ||
for (index = 0; index < 4; index ++, ptr ++) | ||
{ | ||
printf ("%d %d %d\n", index, ref[index], *ptr); | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdio.h> | ||
int main (void) | ||
{ | ||
int * ptr; | ||
int trof[2][2] = {12, 14, 16}; | ||
int trof_2[2][2] = {{12}, {14, 16}}; | ||
|
||
ptr = trof[0]; | ||
printf ("*ptr = %d ptr = %p\n", *ptr, ptr); | ||
printf ("*(ptr + 2) = %d ptr + 2 = %p\n", *(ptr + 2), ptr + 2); | ||
ptr = trof_2[0]; | ||
printf ("*ptr2 = %d ptr2 = %p\n", *ptr, ptr); | ||
printf ("*(ptr2 + 2) = %d ptr2 + 2 = %p\n", *(ptr + 2), ptr + 2); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# ninja log v5 | ||
335 503 1702822896535710815 C_primer 5cb5d6dfc54446d4 | ||
433 1450 1702958014858365474 C_primer d7434207347cad4d | ||
4 335 1702822896367170007 CMakeFiles/C_primer.dir/9_plus/9_plus/9.36.c.o 9f95dd8b31879556 | ||
1 144 1702825381558358062 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635 | ||
0 267 1702717481449984888 CMakeFiles/C_primer.dir/10_plus/10.12.c.o d0b2887c66daa4b1 | ||
0 431 1702958013825178426 CMakeFiles/C_primer.dir/10_plus/10.15.c.o 3cd52d55636f54b | ||
0 305 1702822896335875576 CMakeFiles/C_primer.dir/9_plus/9_plus/9.35.c.o c09ce47479a5514a | ||
1 823 1702825261308715094 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac | ||
3 825 1702825261305992604 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635 | ||
826 962 1702825261443792962 C_primer a3cbc96ef3d4c1f7 | ||
0 110 1702825272983423224 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac | ||
1 138 1702825381555261318 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac | ||
1 144 1702825381558358062 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635 | ||
144 322 1702825381740197165 C_primer a3cbc96ef3d4c1f7 | ||
0 399 1703062779349976926 CMakeFiles/C_primer.dir/10_plus/10.23.c.o 4a833a773a8f433a | ||
403 1098 1703062780055927389 C_primer 81b0a4dcc53c9b5b | ||
1 268 1703062788743730179 CMakeFiles/C_primer.dir/10_plus/10.23.c.o 4a833a773a8f433a | ||
268 702 1703062789201748673 C_primer 81b0a4dcc53c9b5b |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/Applications/CLion.app/Contents/bin/cmake/mac/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/x64/ninja -G Ninja -S /Users/tgspock/Documents/GitHub/learn_c_primer.github.io -B /Users/tgspock/Documents/GitHub/learn_c_primer.github.io/cmake-build-debug | ||
-- Configuring done (0.1s) | ||
-- Configuring done (0.3s) | ||
-- Generating done (0.0s) | ||
-- Build files have been written to: /Users/tgspock/Documents/GitHub/learn_c_primer.github.io/cmake-build-debug |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Start testing: Dec 17 23:03 CST | ||
Start testing: Dec 20 16:59 CST | ||
---------------------------------------------------------- | ||
End testing: Dec 17 23:03 CST | ||
End testing: Dec 20 16:59 CST |
Oops, something went wrong.