int x; /* declare */
x = 4; /* initialize */
int x = 4; /* declare and initialize */
const x = 4;
int *x; /* declare pointer variable */
auto int x; /* Default storage class for local variables */
register int x; /* Store variable in register instead of RAM */
static int x; /* Keep variable during lifetime of the program */
extern int x; /* Reference of a global variable visible to all program files */
/* Basic types */
int x;
float x;
double x;
char x;
char my_string[]; /* String as array of chars */
/* Boolean */
#include <stdbool.h>
bool x;
/* Array */
int arr[5] = {1, 2, 3, 4, 5};
int first_arr = arr[0];
/* Enum */
enum Color {Red, Green, Blue};
/* Struct */
struct User {
char username[50];
char email[50];
};
/* Declare and intialize struct */
struct User user;
strcpy(user.username, "someusername");
strcpy(user.email, "someone@example.com");
/* Union: store different data types in the same memory location */
union Data {
int i;
float f;
char str[10];
}
/* Typedef: alias for a type */
typedef unsigned char BYTE;
/* Define: alias for values */
#define ONE 1
/* Type casting */
double x = 4.
x_converted = (int) x
int my_function(int x) {
int y = 3;
return x + y;
}
void swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}
/* call by value */
my_function(a)
/* call by pointer */
swap(&a, &b)
/* Variable number of parameters */
int my_function(int num, ... ) {
/* statement */
}
/* Recursive function */
unsigned long long int factorial(unsigned int i) {
if (i <= 1) {
return 1;
}
return i * factorial(i - 1);
}