C Language Basics...
Scalar Data Types
~ Scalar data types have a greater than or less than relationship between values
~ Data types are:
~ Character is similar to a very small integer
~ Data types are:
- Character - 1 byte
- Integer - 4 bytes
- Long Integer - 8 bytes
- Floating Point - 4 bytes
- Double Precision - 8 bytes
- Long Double Precision - 16 bytes
~ Character is similar to a very small integer
- value is between 0 & 255 if unsigned
- value is between -128 & 127 if signed
Variable
~ Must be declared before being used
~ Names can contains letters, numbers or underscores
* Variables must NOT start with a number
~ Syntax: datatype variablename;
ex. int counter;
~ Can give a variable a value when it is declared
ex. int counter = 1;
~ Can declare multiple variables at the same time
ex. int counter1, counter2, counter3;
~ Names can contains letters, numbers or underscores
* Variables must NOT start with a number
~ Syntax: datatype variablename;
ex. int counter;
~ Can give a variable a value when it is declared
ex. int counter = 1;
~ Can declare multiple variables at the same time
ex. int counter1, counter2, counter3;
Pointers
~ A variable that holds an address in memory
~ Pointers must have a type
~ Pointers are declared using a *
ex. int *pNumber; // declare a pointer of type int
int Number = 17;
pNumber = &Number; // gets the address of the Number
printf ("Number (%d) is at address %x \n", Number, pNumber);
~ Pointers must have a type
~ Pointers are declared using a *
ex. int *pNumber; // declare a pointer of type int
int Number = 17;
pNumber = &Number; // gets the address of the Number
printf ("Number (%d) is at address %x \n", Number, pNumber);
Arrays
~ A series of values that are all the same type
~ Declared using square brackets [ ] after the variable name
ex. Float grades[30] // 30 objects in the array
~ First value in the array has an index of 0
~ The name of an array, without the index, is a pointer to the first address in the array
~ Declared using square brackets [ ] after the variable name
ex. Float grades[30] // 30 objects in the array
~ First value in the array has an index of 0
~ The name of an array, without the index, is a pointer to the first address in the array
Structures
~ Structures are like an array except the types of the values can be different
~ Index values in a structure using "dot notation"
ex. struct
{
int xCoordinate, yCoordinate;
float color;
}
point.xCoordinate = 10;
point.yCoordinate = 20;
point.color = 1;
printf ("(%d, %d) with color %g. \n", point.xCoordinate, point.yCoordinate,
point.color);
~ Structs are usually declared with "typedef"
~ Index values in a structure using "dot notation"
ex. struct
{
int xCoordinate, yCoordinate;
float color;
}
point.xCoordinate = 10;
point.yCoordinate = 20;
point.color = 1;
printf ("(%d, %d) with color %g. \n", point.xCoordinate, point.yCoordinate,
point.color);
~ Structs are usually declared with "typedef"