<aside> <img src="/icons/home_green.svg" alt="/icons/home_green.svg" width="40px" />

Back to Home

</aside>

Format Specifiers in C: printf and scanf

Basic Structure

#include <stdio.h>

int main() {
    // Your code here
    return 0;
}

Data Types & Variables

Control Structures

// If statement
if (condition) {
    // code
} else if (condition) {
    // code
} else {
    // code
}

// While loop
while (condition) {
    // code
}

// For loop
for (int i = 0; i < n; i++) {
    // code
}

Arrays & Pointers

int array[5] = {1, 2, 3, 4, 5};
int *ptr = &variable;
*ptr = 10; // Dereferencing

Functions

return_type function_name(parameters) {
    // function body
    return value;
}

Memory Management

int *ptr = malloc(size * sizeof(int));
free(ptr); // Always free allocated memory

File Operations

FILE *file = fopen("filename", "mode");
fprintf(file, "text");
fclose(file);

Remember to: