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