Native C

C is a compiled language. This means the compiler needs to take the code, process it and create an executable.
Every statement ends with a semi-colon



Data Types and Modifiers

There are four main data types
char
int - for whole numbers
float - for decimals
double - for decimals


There are also four different modifiers
signed -
unsigned -
short -
long - (there is even long long)


C does not have a boolean data type
It is often defined as follows:

#define BOOL char; 
#define FALSE 0;
#define TRUE 1;


int numbers[10] 
int multi[x][y]
if (true) {
} else if (true)
} else {
}

Other Operators

AND operator &&
OR operator ||
NOT operator !=



Strings are arrays of characters

These are referred to as C-Strings (not to be confused with C++ Strings)

char name[] = "some text";     //automatic 
char name[10] = "some text"; //adding one to the length, to include the string termination character)


Loops

for (i=0; i<10; i++) { 
}

while (true) {
   break / continue
}

Functions

All arguments are passed by value
Must be declared at the top before they are used


\n = newline 

Static Variables
Static functions - the scope is not global, only that file


Pointers are used for

A pointer is a simple integer variable that holds a memory address that points to a value
Strings
Dynamic memory allocation
Function arguments by reference
Building data structures


Dereferencing

This is the name used to describe getting the value that the pointer refers to
You can deference a pointer using the asterisk operator (*)


Addressing
This is the name used to describe getting the pointer in memory for a variable
You can get the address of a variable using the ampersand operator (&)

char c = 'A';  
char *pc = &c;

Structures

These are data types that contain a group of data types (or pointers)

struct point { 
   int x;
   int y;
}

struct point p;
p.x = 10;
p.y = 5
myfunc(p);

TypeDefs

These are structs but allow us to declare an instance of this struct without having to use the struct keyword.
typedef struct {

   int x; 
   int y;
} point;

point p;

Type Casting

Writing = "(person *) malloc(sizeof (person))"
This changes the type of the pointer returned to be person


Library Files - stdio.h

printf


strncmp - compares 2 strings
strlen - returns length of string
strncat - appends characters to the end
sizeof - not an actual function, the compiler interprets and translates it to the actual size
malloc - memory allocation, this returns a "void pointer" which is a pointer that does not have a type
free - does not delete the variable, just the data that it points to
wcsncpy -
strncpy -
wcslen -



Sample Code

#include <stdio.h> 
int main() {
    int x;
    printf("Enter a number: ");
    scanf("%d", &x);
    printf("You entered: %d\n", x);
    return 0;
}


© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext