mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 01:51:38 +00:00
Added missing semicolons and correct some words.
This commit is contained in:
parent
25dbc80b2d
commit
e8910da685
@ -154,7 +154,7 @@ int main() {
|
|||||||
int multi_array[2][5] = {
|
int multi_array[2][5] = {
|
||||||
{1, 2, 3, 4, 5},
|
{1, 2, 3, 4, 5},
|
||||||
{6, 7, 8, 9, 0}
|
{6, 7, 8, 9, 0}
|
||||||
}
|
};
|
||||||
//access elements:
|
//access elements:
|
||||||
int array_int = multi_array[0][2]; // => 3
|
int array_int = multi_array[0][2]; // => 3
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ int main() {
|
|||||||
z = (a > b) ? a : b; // => 10 "if a > b return a, else return b."
|
z = (a > b) ? a : b; // => 10 "if a > b return a, else return b."
|
||||||
|
|
||||||
//Increment and decrement operators:
|
//Increment and decrement operators:
|
||||||
char *s = "iLoveC"
|
char *s = "iLoveC";
|
||||||
int j = 0;
|
int j = 0;
|
||||||
s[j++]; // => "i". Returns the j-th item of s THEN increments value of j.
|
s[j++]; // => "i". Returns the j-th item of s THEN increments value of j.
|
||||||
j = 0;
|
j = 0;
|
||||||
@ -251,7 +251,7 @@ int main() {
|
|||||||
// While loops exist
|
// While loops exist
|
||||||
int ii = 0;
|
int ii = 0;
|
||||||
while (ii < 10) { //ANY value not zero is true.
|
while (ii < 10) { //ANY value not zero is true.
|
||||||
printf("%d, ", ii++); // ii++ increments ii AFTER using it's current value.
|
printf("%d, ", ii++); // ii++ increments ii AFTER using its current value.
|
||||||
} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -259,7 +259,7 @@ int main() {
|
|||||||
int kk = 0;
|
int kk = 0;
|
||||||
do {
|
do {
|
||||||
printf("%d, ", kk);
|
printf("%d, ", kk);
|
||||||
} while (++kk < 10); // ++kk increments kk BEFORE using it's current value.
|
} while (++kk < 10); // ++kk increments kk BEFORE using its current value.
|
||||||
// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -367,7 +367,7 @@ int main() {
|
|||||||
// This works because arrays often decay into pointers to their first element.
|
// This works because arrays often decay into pointers to their first element.
|
||||||
// For example, when an array is passed to a function or is assigned to a pointer,
|
// For example, when an array is passed to a function or is assigned to a pointer,
|
||||||
// it decays into (implicitly converted to) a pointer.
|
// it decays into (implicitly converted to) a pointer.
|
||||||
// Exceptions: when the array is the argument of the `&` (address-od) operator:
|
// Exceptions: when the array is the argument of the `&` (address-of) operator:
|
||||||
int arr[10];
|
int arr[10];
|
||||||
int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`!
|
int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`!
|
||||||
// It's of type "pointer to array" (of ten `int`s).
|
// It's of type "pointer to array" (of ten `int`s).
|
||||||
|
Loading…
Reference in New Issue
Block a user