DEV Community

Cover image for A Small Mistake in C That Took Me 30 Minutes to Fix
Tahami AK SERVICES
Tahami AK SERVICES

Posted on

A Small Mistake in C That Took Me 30 Minutes to Fix

Today I got stuck on a very small problem in C.

And honestly… it took...Read More

The Code

include

int main() {
int a = 5;

if(a = 10) {
    printf("Value is 10");
}

return 0;
Enter fullscreen mode Exit fullscreen mode

}

At first glance, everything looks fine.

But the output was not what I expected.

The Problem

I was using:

if(a = 10)

Instead of:

if(a == 10)
Why This Matters
= is used for assignment
== is used for comparison

So instead of checking the value...Read More

👉 I was actually changing the value of a

That’s why the condition was always true.

What I Learned

This small mistake taught me something important:

👉 Always pay...Read More

Because even a tiny symbol can completely change your program.

Final Thought

Sometimes the bug is not big.

It’s just one small mistake hiding in plain sight.

And those are the... Read More

Thanks for reading.

Top comments (0)