Find Minimum Value of an Array in C

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 2 Code Examples
🚀 Live Preview
Arrays

What You’ll Learn

Finding the minimum in an unsorted array is the twin of the max scan: keep a running winner and update it whenever you see a smaller value. This tutorial covers find_min, sizeof for length, a live preview, worked C examples (mixed positives and all negatives), edge cases, and O(n) complexity.

Running Min

Start at arr[0]

Pick the first element, then beat it with smaller values.

One Pass

Left → right

Visit each index once — no sorting required.

find_min

Reusable helper

Pass the array and size; return the smallest value.

Negatives OK

Most negative

All-negative arrays: the min is the most negative.

Live Preview

Min = 2

Same seven numbers as Example 1, computed in the browser.

O(n)

O(1) space

Same cost story as max; mention empty-array edges.

Introduction

To find the minimum in a 1D array, pick the first element as your provisional winner. For each next element, if it is smaller than the current winner, replace the winner. After the last index, the winner is the minimum.

This is one pass, left to right — the same shape as finding the maximum, with < instead of >. No sorting required.

Why it matters?

It locks in the running-state pattern after the max tutorial — comparisons, O(n) reasoning, and careful handling of negatives and empty arrays.

Key Highlights

Init from arr[0]

Never seed with a magic constant.

Compare with <

Update only when the next value is smaller.

sizeof Length

Count elements without hard-coding.

O(n) / O(1)

One pass; constant extra space.

In short: set min = arr[0], then for each later element if arr[i] < min update min — and require size >= 1.

📝 Problem & Approach

Given a non-empty array of integers, return the smallest value with a single left-to-right scan.

c
/* Array: 12, 5, 7, 3, 2, 8, 10
 * Start min = 12
 * 5 < 12 → min = 5
 * 3 < 5  → min = 3
 * 2 < 3  → min = 2
 */

Inputs & Outputs

ItemTypeDescription
arrconst int[]Input array; not modified by find_min.
sizeintElement count; must be >= 1 for this tutorial.
returnintSmallest value among the size elements.

Minimal workflow

Pseudocode
function find_min(arr, size):   // assume size >= 1
    min ← arr[0]
    for i from 1 to size - 1:
        if arr[i] < min:
            min ← arr[i]
    return min

Method comparison

ApproachCostNotes
Linear scan (this page)O(n)Best for min alone
Sort then take firstO(n log n)Overkill for min only
Find maximumO(n)Same loops; use > instead

⚡ Quick Reference

GoalPattern
Initializemin_val = arr[0];
Updateif (arr[i] < min_val) min_val = arr[i];
Lengthsizeof(array) / sizeof(array[0])
GuardRequire size >= 1 before reading arr[0]
CostO(n) time, O(1) extra space

📋 Min vs Max vs Sort

Related array problems — only min and max share the same single-pass structure.

Minimum
if < update

This page — running min

Maximum
if > update

Previous page — flip the test

Sort then first
O(n log n)

Unnecessary for min alone

Interview tip
arr[0] seed

Avoid INT_MAX unless asked

Context

When This Problem Shows Up

Reach for a running minimum whenever you need the smallest value in an unsorted list.

  1. Interview warm-up

    Natural follow-up after finding the maximum.

  2. Lowest reading

    Smallest score, temperature, or sensor value.

  3. Building block

    Basis for range (max − min) and clamp helpers.

  4. Contrast with sort

    Show why O(n) beats sorting for this goal.

  5. Not for empty arrays

    Validate size before reading arr[0].

Key benefit: one clear scan that mirrors max — prove you can flip the comparison and still handle negatives correctly.

🔮 Live Preview

Uses the same seven integers as Example 1: 12, 5, 7, 3, 2, 8, 10.

Runs the same comparison logic in JavaScript in your browser (no compile needed).

Live result
Press “Find minimum”.

Examples Gallery

Two complete C programs — a mixed sample (min 2) and an all-negative demo (min -9). Click View Output to reveal sample console results.

📚 Getting Started

Initialize from the first element, then scan with <.

Example 1 — Find Minimum (Reference Program)

Matches the classic interview shape: find_min, a sample array, and length from sizeof. Uses int main(void). The minimum is 2.

c
#include <stdio.h>

int find_min(const int arr[], int size) {
    int min_val = arr[0];

    for (int i = 1; i < size; ++i) {
        if (arr[i] < min_val) {
            min_val = arr[i];
        }
    }

    return min_val;
}

int main(void) {
    int array[] = {12, 5, 7, 3, 2, 8, 10};
    int size = (int)(sizeof(array) / sizeof(array[0]));
    int min_value = find_min(array, size);

    printf("Minimum value in the array: %d\n", min_value);

    return 0;
}

How It Works

const int arr[] tells the reader (and the compiler) that this function will not change the array through arr. The cast on sizeof keeps size as int here; for huge arrays in real code, size_t is often nicer.

📈 Practical Patterns

Same function still works when every value is negative.

Example 2 — When Every Element Is Negative

Smallest still means “leftmost on the number line.” Here the minimum is −9, not −1.

c
#include <stdio.h>

int find_min(const int arr[], int size) {
    int min_val = arr[0];
    for (int i = 1; i < size; ++i) {
        if (arr[i] < min_val) {
            min_val = arr[i];
        }
    }
    return min_val;
}

int main(void) {
    int negatives[] = {-9, -3, -1, -7};
    int n = (int)(sizeof(negatives) / sizeof(negatives[0]));

    printf("Minimum (most negative): %d\n", find_min(negatives, n));

    return 0;
}

How It Works

Starting at -9, later values are larger, so the min stays -9. Never initialize with 0 when negatives are possible — 0 would wrongly win as the “minimum.”

🧠 How the Algorithm Finds the Minimum

1

Check length

Assume size >= 1. If length can be zero, handle that before reading arr[0].

Guard
2

Initialize

Set min = arr[0].

Seed
3

Scan

For i from 1 to size - 1, if arr[i] < min, set min = arr[i].

Compare
=

Return min

For the reference array, the answer is 2.

🔎 Worked Walkthrough — Reference Array

Trace the running minimum for {12, 5, 7, 3, 2, 8, 10}.

iarr[i]Comparemin after
12seed12
155 < 12? yes5
277 < 5? no5
333 < 5? yes3
422 < 3? yes2
588 < 2? no2
61010 < 2? no2

Final answer: 2.

Use Cases

Where a running-minimum scan shows up beyond the interview prompt.

1. Loop Practice

Master index loops and comparisons.

Example: twin of the max drill.

2. Floor Values

Lowest score, temperature, or reading.

Example: sensor batches.

3. Complexity Talk

Lead into O(n) vs sorting follow-ups.

Example: interview Q&A.

4. Signed Data

Prove most-negative wins among negatives.

Example: Example 2.

5. Pair with Max

Same loops; flip the comparison.

Example: previous tutorial.

6. Edge Awareness

Discuss empty and single-element arrays.

Example: production guards.

Pro Tip: say “seed from arr[0], then update on <” before writing the loop — and mention empty arrays if asked.

Advantages

Why the linear scan earns interview points.

  1. 1. Optimal for Min Alone

    You must look at every element at least once; one pass is enough.

  2. 2. Constant Extra Space

    Only a few scalars besides the input array.

  3. 3. Works with Negatives

    Seeding from arr[0] handles all-negative data.

  4. 4. Easy to Trace

    Whiteboard the running min cell by cell.

Pro Tip: do not sort first unless you need the full order — mention that if the interviewer probes alternatives.

Usage Tips

Small habits that keep min-finding code clean in interviews.

  1. 1. Seed from arr[0]

    Avoid magic constants like 0 or INT_MAX unless required.

  2. 2. Loop from Index 1

    You already accounted for index 0 as the seed.

  3. 3. Guard Empty Arrays

    State that size >= 1 or return an error path.

  4. 4. Use sizeof Carefully

    It works on real arrays, not decayed pointers in callees.

  5. 5. Quote O(n)

    Mention you do not need to sort for min alone.

Pro Tip: the walkthrough table is the fastest way to lock in updates before typing the loop.

Common Pitfalls

Mistakes that commonly break minimum-finding solutions in C.

  1. 1. Seeding with 0

    Fails when every element is negative (0 looks smaller than all of them? No — 0 is larger, so you miss the true min).

    → Always seed from arr[0] (or a true upper bound).

  2. 2. Empty Array Access

    Reading arr[0] when size == 0 is undefined.

    → Validate length before the scan.

  3. 3. sizeof on a Pointer

    Inside a function that received a decayed pointer, sizeof is wrong.

    → Pass size explicitly from the caller.

  4. 4. Sorting First

    Wastes work when you only need the min.

    → Prefer the linear scan.

  5. 5. Confusing Min with Max Among Negatives

    Among {-9, -3, -1}, min is -9, max is -1.

    → Keep “leftmost on the number line” in mind.

Edge Cases

Check these before calling the solution done.

Empty

size == 0

There is no minimum; do not access arr[0] until you know the length is at least one.

One element

size == 1

The loop never runs; min_val stays that single element, which is correct.

Negatives

All negative

Min is the most negative; seeding from arr[0] handles it.

Duplicates

Repeated min

Returning the value is fine; index-of-min needs an explicit tie policy.

INT_MAX

Extreme ints

Seeding from data still works when INT_MAX or INT_MIN appears.

Floats

Floating-point

Same structure with double; be careful with NaN in numerical code.

🔄 Input / Output

These programs use fixed numbers inside the code. To read values from the keyboard, use scanf in a loop, fill an array, then call find_min with the count you read.

SampleResult
{12, 5, 7, 3, 2, 8, 10}2
{-9, -3, -1, -7}-9

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Trace a new array

  • Use {8, 1, 4, 1, 6}
  • Confirm min is 1

2. Return the index

  • Track both value and index
  • Decide first vs last on ties

3. Single-element case

  • Call with size == 1
  • Verify the loop never runs

4. Flip to maximum

  • Change < to >
  • Reconnect with the previous tutorial

Notes

  • Algorithm: keep a running minimum while scanning once.
  • Cost: O(n) time, O(1) extra space.
  • Edge: decide what to do when n = 0.
  • Seed from data so all-negative arrays still work (min is the most negative).

Quick Takeaway: seed min from arr[0], update on <, require a non-empty array, and quote O(n).

⏱️ Time and Space Complexity

ApproachTimeExtra space
Single scanO(n)O(1)
Wrap Up

🎉 Conclusion

Finding the minimum is a one-pass running comparison: seed from the first element, update whenever a smaller value appears, and return the winner. Master both the mixed and all-negative samples so you can explain negatives and empty-array edges confidently.

Practice both examples above, then continue to the multiplication table for a classic nested-loop warm-up.

min = arr[0], then update on arr[i] < min — with size >= 1.

💡 Best Practices

✅ Do

  • Seed the min from arr[0]
  • Require size >= 1 (or handle empty)
  • Pass size explicitly into helpers
  • Dry-run one mixed and one negative case
  • Quote O(n) time and O(1) space

❌ Don’t

  • Initialize min to 0 blindly
  • Read arr[0] when the array is empty
  • Use sizeof on a decayed pointer
  • Sort just to find the min
  • Confuse most-negative with least-negative

Key Takeaways

Knowledge Unlocked

Five things to remember about finding the min in C

Implement it the interview-friendly way.

5
Core concepts
< 02

Update

On smaller

Scan
1 03

Pass

One loop

Code
04

Signs

Most negative

Edge
O 05

Cost

O(n)

Analysis

❓ Frequently Asked Questions

It is the smallest number in the list. If you wrote all values on a line, it is the one farthest to the left on the number line (the most negative, or the smallest positive if everything is positive).
You need a first guess taken from the data. The first slot is a fair starting point. Then each later number can replace that guess if it is smaller.
With zero elements there is no smallest value. Real programs should check the length first and avoid reading arr[0]. This lesson assumes at least one element so the idea stays simple.
Yes. You still begin with the first element. Smaller means closer to negative infinity, so among {-9, -3, -1} the answer is -9.
That is fine. You still print that value once; duplicates do not change which number is smallest.
No. Sorting costs more work than one scan. To find only the minimum, walking the array once is enough.
You look at each of the n items once: O(n) time and O(1) extra space besides the array itself.
Same structure; flip the comparison to > and keep a running maximum instead.

Did you Know? 🔊

Finding the smallest value in an unsorted list still takes a single left-to-right pass: O(n) time and O(1) extra memory. You cannot do better in the worst case without extra structure, because any unseen element could be the new minimum.

Continue to Multiplication Table

Learn how to print a multiplication table with nested loops in C.

Multiplication Table tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful