1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-12 09:44:24 +02:00

Add more shorthand notes, array notes to C

This commit is contained in:
Levi Bostian
2013-08-31 16:24:56 -05:00
parent b0c5ca0a1c
commit 5c711eb30f

View File

@@ -166,6 +166,10 @@ int main() {
int i1 = 1, i2 = 2; // Shorthand for multiple declaration
float f1 = 1.0, f2 = 2.0;
//more shorthands:
int a, b, c;
a = b = c = 0;
// Arithmetic is straightforward
i1 + i2; // => 3
i2 - i1; // => 1
@@ -339,7 +343,7 @@ int main() {
printf("%d\n", x); // => Prints 1
// Arrays are a good way to allocate a contiguous block of memory
int x_array[20];
int x_array[20]; //declares array of size 20 (cannot change size)
int xx;
for (xx = 0; xx < 20; xx++) {
x_array[xx] = 20 - xx;