# iso646

***

**1. Character Constants**

```c
#include <iso646.h>

int main() {
    char c = NUL;  // null character
    return 0;
}
```

**2. Arithmetic Operators**

```c
#include <iso646.h>

int main() {
    int a = 10, b = 5;
    int sum = a + b, diff = a - b, prod = a * b;
    return 0;
}
```

**3. Logical Operators**

```c
#include <iso646.h>

int main() {
    int a = 1, b = 0;
    int and = a && b, or = a || b, not = !a;
    return 0;
}
```

**4. Bitwise Operators**

```c
#include <iso646.h>

int main() {
    int a = 10, b = 5;
    int and = a & b, or = a | b, xor = a ^ b, shl = a << 2, shr = a >> 2;
    return 0;
}
```

**5. Relational Operators**

```c
#include <iso646.h>

int main() {
    int a = 10, b = 5;
    int eq = a == b, ne = a != b, lt = a < b, gt = a > b, le = a <= b, ge = a >= b;
    return 0;
}
```

**6. Assignment Operators**

```c
#include <iso646.h>

int main() {
    int a;
    a = 10;  // simple assignment
    a += 5;  // addition assignment
    a -= 5;  // subtraction assignment
    return 0;
}
```

**7. Increment/Decrement Operators**

```c
#include <iso646.h>

int main() {
    int a = 10;
    a++;  // post-increment
    ++a;  // pre-increment
    return 0;
}
```

**8. Conditional Operator**

```c
#include <iso646.h>

int main() {
    int a = 10, b = 5;
    int max = (a > b) ? a : b;
    return 0;
}
```

**9. Casting Operators**

```c
#include <iso646.h>

int main() {
    int a = 10;
    double b = (double)a;
    return 0;
}
```

**10. Sizeof Operator**

```c
#include <iso646.h>

int main() {
    int a = 10;
    size_t size = sizeof(a);
    return 0;
}
```

**11. Pointer Arithmetic**

```c
#include <iso646.h>

int main() {
    int arr[5];
    int *ptr = arr;
    *ptr++ = 10;
    return 0;
}
```

**12. Array Subscripting**

```c
#include <iso646.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    arr[2] = 10;
    return 0;
}
```

**13. Structure Member Access**

```c
#include <iso646.h>

struct Point {
    int x;
    int y;
};

int main() {
    struct Point p = {10, 20};
    p.x = 15;
    return 0;
}
```

**14. Function Invocation**

```c
#include <iso646.h>

void greet(void) {
    printf("Hello, world!\n");
}

int main() {
    greet();
    return 0;
}
```

**15. Preprocessor Macros**

```c
#include <iso646.h>

#define PI 3.14159

int main() {
    double circumference = 2 * PI * 10;
    return 0;
}
```

**16. Storage Classes**

```c
#include <iso646.h>

static int a = 10;  // static variable

int main() {
    auto int b = 20;  // automatic variable
    return 0;
}
```

**17. Scope Rules**

```c
#include <iso646.h>

int global = 10;

void outer() {
    int local = 20;
    {
        int nested = 30;
        printf("%d %d %d\n", global, local, nested);
    }
}

int main() {
    outer();
    return 0;
}
```

**18. Unions**

```c
#include <iso646.h>

union Data {
    int i;
    float f;
};

int main() {
    union Data d;
    d.i = 10;
    printf("%f\n", d.f);
    return 0;
}
```

**19. Enumerations**

```c
#include <iso646.h>

enum Color {
    RED,
    GREEN,
    BLUE
};

int main() {
    enum Color color = RED;
    return 0;
}
```

**20. Bit Fields**

```c
#include <iso646.h>

struct Data {
    unsigned char a : 3;
    unsigned char b : 5;
};

int main() {
    struct Data d = {0, 0};
    d.a = 2;
    d.b = 10;
    return 0;
}
```

**21. Variable-Length Arrays (VLAs)**

```c
#include <iso646.h>

int main() {
    int n = 10;
    int arr[n];
    return 0;
}
```

**22. Flexible Array Members (FAMs)**

```c
#include <iso646.h>

struct Data {
    int *arr;
    size_t size;
};

int main() {
    struct Data d = {NULL, 0};
    d.arr = malloc(sizeof(int) * 10);
    d.size = 10;
    return 0;
}
```

**23. Initialization Lists**

```c
#include <iso646.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    return 0;
}
```

**24. Compound Literals**

```c
#include <iso646.h>

int main() {
    int *ptr = (int[]){1, 2, 3, 4, 5};
    return 0;
}
```

**25. Designated Initializers**

```c
#include <iso646.h>

struct Point {
    int x;
    int y;
};

int main() {
    struct Point p = {.x = 10, .y = 20};
    return 0;
}
```

**26. Thread-Local Storage (TLS)**

```c
#include <iso646.h>

__thread int a = 10;

int main() {
    return 0;
}
```

**27. Function Pointers**

```c
#include <iso646.h>

int add(int a, int b) {
    return a + b;
}

int main() {
    int (*ptr)(int, int) = add;
    ptr(1, 2);
    return 0;
}
```

**28. Dynamic Memory Allocation**

```c
#include <iso646.h>

int *ptr = malloc(sizeof(int));

int main() {
    *ptr = 10;
    free(ptr);
    return 0;
}
```

**29. Variable-Argument Macros**

```c
#include <iso646.h>

#define SPRINTF(buf, fmt, ...) snprintf(buf, sizeof buf, fmt, __VA_ARGS__)

int main() {
    char buf[100] = "";
    SPRINTF(buf, "Hello, %s!\n", "world");
    printf("%s", buf);
    return 0;
}
```

**30. Inline Functions**

```c
#include <iso646.h>

inline int square(int n) {
    return n * n;
}

int main() {
    int result = square(10);
    return 0;
}
```

**31. Restrictions on Variable Assignment**

```c
#include <iso646.h>

int main() {
    const int a = 10;
    a = 20;  // error: cannot assign to a const variable
    return 0;
}
```

**32. Undefined Behavior**

```c
#include <iso646.h>

int main() {
    int *ptr;
    *ptr = 10;  // error: accessing uninitialized pointer
    return 0;
}
```

**33. Aliasing**

```c
#include <iso646.h>

int main() {
    int a[5];
    int *ptr = a;
    a[0] = 10;
    *ptr = 20;  // same memory location, updating both a[0] and *ptr
    return 0;
}
```

**34. Pointer Casting**

```c
#include <iso646.h>

int main() {
    int *ptr = (int *)0x1234;  // explicit pointer cast to avoid undefined behavior
    return 0;
}
```

**35. Memory Barriers**

```c
#include <iso646.h>

void write_to_shared_memory(int *ptr, int value) {
    *ptr = value;
    __sync_synchronize();  // memory barrier
}

int main() {
    int *shared_mem;
    write_to_shared_memory(shared_mem, 10);
    return 0;
}
```

**36. Atomic Operations**

```c
#include <iso646.h>

#include <stdatomic.h>

int main() {
    atomic_int count = ATOMIC_VAR_INIT(0);
    atomic_fetch_add(&count, 1);  // atomic increment
    return 0;
}
```

**37. Thread Synchronization**

```c
#include <iso646.h>

#include <pthread.h>

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void *thread_func(void *arg) {
    pthread_mutex_lock(&mutex);  // lock mutex
    // critical section
    pthread_mutex_unlock(&mutex);  // unlock mutex
    return NULL;
}

int main() {
    pthread_t tid;
    pthread_create(&tid, NULL, thread_func, NULL);
    pthread_join(tid, NULL);
    return 0;
}
```

**38. Signal Handling**

```c
#include <iso646.h>

#include <signal.h>

void sig_handler(int signum) {
    printf("Signal %d received!\n", signum);
}

int main() {
    signal(SIGINT, sig_handler);  // register signal handler for SIGINT
    while (1) {
        // do something
    }
    return 0;
}
```

**39. Error Handling**

```c
#include <iso646.h>

#include <errno.h>

int main() {
    FILE *fp = fopen("myfile.txt", "r");
    if (fp == NULL) {
        perror("fopen");  // print error message
        return -1;
    }
    return 0;
}
```

**40. Floating-Point Arithmetic**

```c
#include <iso646.h>

#include <math.h>

int main() {
    double x = sqrt(2);
    return 0;
}
```

**41. Complex Arithmetic**

```c
#include <iso646.h>

#include <complex.h>

int main() {
    complex double x = 1 + 2i;
    return 0;
}
```

**42. Character Handling**

```c
#include <iso646.h>

#include <ctype.h>

int main() {
    char c = 'a';
    if (isalpha(c)) {
        // do something
    }
    return 0;
}
```

**43. String Handling**

```c
#include <iso646.h>

#include <string.h>

int main() {
    char str[] = "Hello, world!";
    strlen(str);  // get string length
    strcpy(str, "Goodbye, world!");  // copy string
    return 0;
}
```

**44. Date and Time Functions**

```c
#include <iso646.h>

#include <time.h>

int main() {
    time_t now = time(NULL);
    return 0;
}
```

**45. Random Number Generation**

```c
#include <iso646.h>

#include <stdlib.h>

int main() {
    srand(time(NULL));  // initialize random number generator
    int r = rand();  // generate random number
    return 0;
}
```

**46. Input and Output**

```c
#include <iso646.h>

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    scanf("%d", &n);  // read integer from standard input
    return 0;
}
```

**47. File I/O**

```c
#include <iso646.h>

#include <stdio.h>

int main() {
    FILE *fp = fopen("myfile.txt", "w");
    fprintf(fp, "Hello, world!\n");
    fclose(fp);
    return 0;
}
```

**48. Process Control**

```c
#include <iso646.h>

#include <stdlib.h>

int main() {
    if (fork() == 0) {
        // child process
    } else {
        // parent process
    }
    return 0;
}
```

**49. Network Programming**

```c
#include <iso646.h>

#include <sys/socket.h>

int main() {
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    return 0;
}
```

**50. Multithreading**

```c
#include <iso646.h>

#include <pthread.h>

void *thread_func(void *arg) {
    // thread function
    return NULL;
}

int main() {
    pthread_t tid;
    pthread_create(&tid, NULL, thread_func, NULL);
    pthread_join(tid, NULL);
    return 0;
}
```
