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
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().
#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.
int factorial(int n) { if (n == 0) return 1; // Base Case else return n * factorial(n - 1); // Recursive Call }
Arrays
Data Structures
A collection of variables of the same type. Index starts at 0.
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.
Strings
Character Arrays
A string is a char array ending with a Null Terminator \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") |
Pointers
Memory Management
A pointer stores the memory address of another variable.
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
Quiz
Test Your Knowledge
Quiz Complete!
You scored 0 out of 0
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)