Added missing semicolons and correct some words.

This commit is contained in:
Nattaphoom Ch 2014-05-28 01:06:24 +07:00
parent 25dbc80b2d
commit e8910da685

View File

@ -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).
@ -387,7 +387,7 @@ int main() {
// You can also dynamically allocate contiguous blocks of memory with the // You can also dynamically allocate contiguous blocks of memory with the
// standard library function malloc, which takes one argument of type size_t // standard library function malloc, which takes one argument of type size_t
// representing the number of bytes to allocate (usually from the heap, although this // representing the number of bytes to allocate (usually from the heap, although this
// may not be true on e. g. embedded systems - the C standard says nothing about it). // may not be true on e.g. embedded systems - the C standard says nothing about it).
int *my_ptr = malloc(sizeof(*my_ptr) * 20); int *my_ptr = malloc(sizeof(*my_ptr) * 20);
for (xx = 0; xx < 20; xx++) { for (xx = 0; xx < 20; xx++) {
*(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx
@ -405,7 +405,7 @@ int main() {
// Strings are arrays of char, but they are usually represented as a // Strings are arrays of char, but they are usually represented as a
// pointer-to-char (which is a pointer to the first element of the array). // pointer-to-char (which is a pointer to the first element of the array).
// It's good practice to use `const char *' when referring to a string literal, // It's good practice to use `const char *' when referring to a string literal,
// since string literals shall not be modified (i. e. "foo"[0] = 'a' is ILLEGAL.) // since string literals shall not be modified (i.e. "foo"[0] = 'a' is ILLEGAL.)
const char *my_str = "This is my very own string literal"; const char *my_str = "This is my very own string literal";
printf("%c\n", *my_str); // => 'T' printf("%c\n", *my_str); // => 'T'