C Basics
Posted on January 11th, 2010
The basics of C are primarily in understanding the language and how to solve problems with it. C is a sequential programming language, which means that statements are read line by line and instructions are fead to the processor in this linear order. Of course preprocessor directives and the goto statement can change this, but for the most part this rule is consistent.
It is a good strategy to learn which library functions should be included in order to write a good program. Often times, you will want to use I/O, math, strings, etc. When you need to use more complex objects in programming, it is easier to use libraries that have been written, or to write your own. I will cover some advanced topics such as these later on.
Data Types
It is important to understand how to create and use data types or variables in C. The various types are: integer (int), floating point (float), character (char), long integer (long), longer float (double), etc.
To declare a variable, you must write the word in the parenthesis and then a name for that variable. The name must not start with a number, any letter or underscore is acceptable. It must not be a reserved word, which is a part of the defined C language i.e int, float, for, if, etc. An assignment can be made with the ‘=’ operator. Here is an example:
int sum = 0; // This is an integer named sum which is “given the value” of 0.
Once the variable is defined, the data type no longer needs to be stated, in this example it is int. To use the variable you must use the name which is sum and do an operation on it.
More to come soon!