Monday, December 19, 2011

Collecting Data Items of Different Types


The art of programming is the art of organizing complexity.
—W. W. Dijkstra
In Hour 12, "Storing Similar Data Items," you learned how to store data of the same type into arrays. In this hour, you'll learn to use structures to collect data items that have different data types. The following topics are covered in this lesson:

More Data Types and Functions


That's all there is, there isn't any more.
—E. Barrymore
In Hour 4, "Data Types and Names in C," you learned about most of the data types, such as char, int, float, and double. In Hour 15, "Functions in C," you learned the basics of using functions in C. In this hour, you'll learn more about data types and functions from the following topics:

Allocating Memory


It's just as unpleasant to get more than you bargain for as to get less.
—G. B. Shaw
So far you've learned how to declare and reserve a piece of memory space before it is used in your program. For instance, you have to specify the size of an array in your program (or the compiler has to figure out the size if you declare an unsized array) before you assign any data to it at runtime. In this lesson you'll learn to allocate memory space dynamically when your program is running. The four dynamic memory allocation functions covered in this lesson are

Applying Pointers


Think twice and do once.
—Chinese proverb
In Hour 11, "An Introduction to Pointers," you learned the basics of using pointers in C. Because pointers are very useful in programming, it's worth spending another hour to learn more about them. In this lesson, the following topics are discussed:

Functions in C


Form follows function.
—L. H. Sullivan
In Hour 14, "Scope and Storage Classes in C," you might have noticed that a function definition is always given first, before the function is called from a main() function. In fact, you can put a function definition anywhere you want, as long as you keep the function declaration at the first place before the function is called. You'll learn about many function features from the following topics covered in this lesson:

Sunday, December 18, 2011

Scope and Storage Classes in C


Nobody owns anything and all anyone has is the use of his presumed possessions.
—P. Wylie
In the previous hours, you've learned how to declare variables of different data types, as well as to initialize and use those variables. It's been assumed that you can access variables from anywhere. Now, the question is: Can we declare variables that are accessible only to certain portions of a program? In this lesson you'll learn about the scope and storage classes of data in C. The main topics covered in this lesson are

Manipulating Strings


I have made this letter longer than usual, because I lack the time to make it short.
—B. Pascal
In the last hour's lesson you learned how to use arrays to collect variables of the same type. You also learned that a character string is actually a character array ended with a null character \0. In this lesson you'll learn more about strings and C functions that can be used to manipulate strings. The following topics are covered:

Storing Similar Data Items


Gather up the fragments that remain, that nothing be lost.
—John 6:12
In last hour's lesson you learned about pointers and the concept of indirection. In this lesson you'll learn about arrays, which are collections of similar data items and are closely related to pointers. The main topics covered in this lesson are

An Introduction to Pointers


The duties of the Pointer were to point out, by calling their names, those in the congregation who should take note of some point made in the sermon.
—H. B. Otis, Simple Truth
You've learned about many important C data types, operators, functions, and loops in the last 10 hours. In this lesson you'll learn about one of the most important and powerful features in C: pointers. The topics covered in this
hour are

Getting Controls


Hour 10 - Getting Controls
It is harder to command than to obey.
—F. Nietzsche
In Hour 7, "Doing the Same Thing Over and Over," you learned to use the for, while, and do-while statements to do the same things over and over. These three statements can be grouped into the looping category that is a part of the control flow statements in C.
In this lesson you'll learn about the statements that belong to another group of control flow statements—conditional branching (or jumping), such as

Playing with Data Modifiers and Math Functions


Hour 9 - Playing with Data Modifiers and Math Functions
If at first you don't succeed, transform your data.
—Murphy's Laws of Computers
In Hour 4, "Data Types and Names in C," you learned about several data types, such as char, int, float, and double, in the C language. In this hour, you'll learn about four data modifiers that enable you to have greater control over the data. The C keywords for the four data modifiers are
  • signed
  • unsigned
  • short
  • long
You're also going to learn about several mathematical functions provided by the C language, such as

Saturday, December 17, 2011

More Operators


Hour 8 - More Operators
Civilization advances by extending the number of important operations we can perform without thinking about them.
—A. N. Whitehead
In Hour 6, "Manipulating Data with Operators," you learned about some important operators in C, such as the arithmetic assignment operators, the unary minus operator, the increment and decrement operators, and the relational operators. In this lesson you'll learn about more operators, including
  • The sizeof operator
  • Logical operators
  • Bit-manipulation operators
  • The conditional operator

Tuesday, December 13, 2011

Doing the Same Thing Over and Over

Hour 7 - Doing the Same Thing Over and Over
Heaven and earth:
Unheard sutra chanting
Repeated…
-Zen saying
In the previous lessons, you've learned the basics of the C program, several important C functions, standard I/O, and some useful operators. In this lesson you'll learn a very important feature of the C language-looping. Looping, also called iteration, is used in programming to perform the same set of statements over and over until certain specified conditions are met.
Three statements in C are designed for looping:
"    The for statement

Manipulating Data with Operators

Hour 6 - Manipulating Data with Operators
"The question is," said Humpty Dumpty, "which is to be master-that's all."
-L. Carroll
You can think of operators as verbs in C that let you manipulate data. In fact, you've learned some operators, such as + (addition), - (subtraction), * (multiplication), / (division), and % (remainder), in Hour 3, "The Essentials of C Programs." The C language has a rich set of operators. In this hour, you'll learn about more operators, such as
"    Arithmetic assignment operators

Reading from and Writing to Standard I/O


Hour 5 - Reading from and Writing to Standard I/O
I/O, I/O, it's off to work we go…
–The Seven Dwarfs (sort of)
In the last lesson you learned how to print out characters, integers, and floating-point numbers to the screen by calling the printf() function. In this lesson you're going to learn more about printf(), as well as about the following functions, which are necessary to receive the input from the user or print the output to the screen:
  • The getc() function
  • The putc() function

Data Types and Names in C


Hour 4 - Data Types and Names in C
What's in a name? That which we call a rose
By any other name would smell as sweet.
—W. Shakespeare
You learned how to make a valid name for a C function in Hour 3, "The Essentials of C Programs." Now, you're going to learn more about naming a variable and the C keywords reserved by the C compiler in this hour.
Also in this hour you're going to learn about the four data types of the C language in detail: