C tutorial : C Language Refresher



C tutorial : C Language Refresher








Sample of the pdf document :



Variables and Types
C is a statically-typed, imperative language. Variables and their types must be declared before use.
double pi = 3.14159265358979;
float x = 0.5;
char c = ’a’;
int a = 42;
int b;
e values of variables change, but not the types.
a = a * 10;
b = a + 1;


Structure and Array Types
Structures are groups of values behaving as a single variable.
struct city
{
int population;
float latitude;
float longitude;
};
Arrays are contiguous blocks of values, all of the some type.
int n[10];
struct city capitals[50];


Pointer
A C pointer is an address in RAM.
int i = 10; // i is a normal integer variable.
int *p = &i; // p refers to the location of i.
e & operator gives “the address of ” a variable
i = 42;
*p = 42;
e * operator gives “the variable at” an address.


Pointers
A C string is a pointer to a zero-terminated array of chars.
char *filename = "teapot.obj"

Pointers and arrays are interchangeable.

int a[10];
int *p = a;
a[5] = 12;
p[5] = 12;


Functions
Functions are declared with arguments and return type.
int average(int a, int b)
{
return (a + b) / 2;
}
Calling this function. . .
x = average(2, 8);


Conditionals
if (value == 0)
{
answer = "false";
}
else
{
answer = "true";
}
Rememb





 Click here for  Download PDF / FREE

C tutorial : C Language Refresher







0 commentaires: