#include <stdio.h>
void swap(int *a, int *b){ int tmp = *a;
*a = *b; *b = tmp;}
int main(void){ int x = 4; int y = 2;
swap(&x, &y); printf("%d %d\n", x, y); return 0;}
#include <stdio.h>#include <stdlib.h>
struct node { int value; struct node *next;};
struct node *push(struct node *head, int value){ struct node *node = malloc(sizeof(*node));
if (node == NULL) return head; node->value = value; node->next = head; return node;}
int main(void){ struct node *list = NULL;
for (int i = 1; i <= 3; i++) list = push(list, i); while (list != NULL) { struct node *next = list->next;
printf("%d\n", list->value); free(list); list = next; } return 0;}
#include <stdio.h>#include <string.h>
void reverse(char *str){ size_t left = 0; size_t right = strlen(str);
while (right > left + 1) { right--; char tmp = str[left]; str[left] = str[right]; str[right] = tmp; left++; }}
int main(void){ char word[] = "stack";
reverse(word); printf("%s\n", word); return 0;}
#include <stdio.h>#include <stdlib.h>#include <string.h>
char *duplicate(const char *src){ size_t len = strlen(src); char *copy = malloc(len + 1);
if (copy == NULL) return NULL; memcpy(copy, src, len + 1); return copy;}
int main(void){ char *name = duplicate("Grady");
name = duplicate("Ada"); if (name == NULL) return 1; printf("%s\n", name); free(name); return 0;}