C Master

Ace Your C Exam

A complete, mobile-friendly reviewer for college students covering Functions, Arrays, Strings, and Pointers.

Learn

Comprehensive content

Quiz

Test your knowledge

AI Chat

Get instant help

Practice

Real examples

01

Functions

Modular Programming

What & Why?

A function is a block of code that performs a specific task. Every C program has at least one function: main().

Declaration The "Prototype". Tells compiler function exists.
Definition The "Body". The actual code logic.
Call Executing the function.
basic_function.c
#include <stdio.h>

// 1. Declaration (Prototype)
int add(int a, int b); 

int main() {
    int sum = add(5, 10); // 3. Call
    printf("Sum: %d", sum);
    return 0;
}

// 2. Definition
int add(int a, int b) {
    return a + b;
}

Recursion

A function calling itself. Must have a Base Case to stop infinite recursion.

factorial.c
int factorial(int n) {
    if (n == 0) 
        return 1; // Base Case
    else 
        return n * factorial(n - 1); // Recursive Call
}
02

Arrays

Data Structures

A collection of variables of the same type. Index starts at 0.

int arr[5] = {10, 20, 30, 40, 50};
idx 0
10
idx 1
20
idx 2
30
idx 3
40
idx 4
50

2D Arrays (Matrices)

Syntax: type name[rows][cols];

int matrix[2][3] = {
    {1, 2, 3},  // Row 0
    {4, 5, 6}   // Row 1
};
// Accessing number 6:
int val = matrix[1][2];  // Row 1, Column 2

Critical Rule

When you pass an array to a function, you are passing the memory address. Changes inside the function affect the original array.

03

Strings

Character Arrays

A string is a char array ending with a Null Terminator \0.

char str[] = "Hello";
'H'
'e'
'l'
'l'
'o'
\0

String Library Functions (<string.h>)

Function Purpose Example
strlen(s) Length (excluding \0) strlen("Hi") → 2
strcpy(dst, src) Copy src to dst strcpy(d, "Text")
strcmp(s1, s2) Compare (0 if equal) strcmp("a","a") → 0
strcat(dest, src) Append src to dest strcat(s1, " more")
04

Pointers

Memory Management

A pointer stores the memory address of another variable.

&
Address-of
"Where does it live?"
*
Dereference
"What is inside that address?"

Basic Pointer Usage

int x = 10;
int *ptr = &x;     // ptr holds address of x

printf("Value: %d\n", *ptr);      // Prints: 10
printf("Address: %p\n", ptr);     // Prints memory address

*ptr = 20;                // x is now 20
05

Quiz

Test Your Knowledge

Quiz Progress 0/0 answered

Practical: Super Calculator

Combines Functions, Switch Cases, and Parameters.

#include <stdio.h>

// Function prototypes
float add(float a, float b) { return a + b; }
float subtract(float a, float b) { return a - b; }
float multiply(float a, float b) { return a * b; }
float divide(float a, float b) {
    if (b == 0) {
        printf("Error! Division by zero.\n");
        return 0;
    }
    return a / b;
}

int main() {
    float n1, n2;
    char op;
    
    printf("Enter (e.g. 10 + 5): ");
    scanf("%f %c %f", &n1, &op, &n2);
    
    switch(op) {
        case '+':
            printf("Result: %.2f", add(n1, n2));
            break;
        case '*':
            printf("Result: %.2f", multiply(n1, n2));
            break;
        default:
            printf("Invalid operator");
    }
    return 0;
}

Quick Cheat Sheet

Topic Syntax Note
Function int func(int x); Declare before main
Array int a[5]; Index 0 to 4
String char s[10]; Needs \0 terminator
Pointer int *p = &x; *p gets value, p gets addr
2D Array int m[3][4]; matrix[row][col]
Recursion return n * f(n-1); Needs base case

Practice Tips

  • Compile with warnings: gcc -Wall -Wextra file.c
  • Use online compilers: onlinegdb.com, replit.com
  • Write small test programs for each concept
  • Trace code with pen and paper (pointers & recursion)