I am getting different outputs for same code on DevC++ and replit. Why is this happening?

Question:

Current behavior: 300 200

Desired behavior: 0 200

Repl link:

code snippet

@KumarSandeep2 can you send us the link to the repl vs a screenshot of the code on devc++?

1 Like

Sir here are the codes and outputs of both the compilers.

Above is the output for DevC++
And I am getting 300 200 instead of 0 200

thats only the output of devc++, can you send a screenshot of the code aswell and the link to the repl which the code is in?

Here is the screenshot of code in DevC++
And the link for replit code is pasted below
https://replit.com/@KumarSandeep2/Exam-1#main.c

it seems that the issue is that the if statement is not a true if statement, as the block inside of it needs to be put inside of a bracket

if (a>=400) {
    #code here
}

replit uses clang by default which appears to set b to 300 initially to avoid (what it thinks will be) the cost of changing it to 300 on line 6, taking the liberty because nowhere in your code is b set to a value.
you should’ve got a warning about this, but they’re disabled by default :person_facepalming:
Run in Shell:

sed -i 's/Wno-everything/Wmost/' Makefile
1 Like

Si in that case my output will be wrong.
Because same code in DevC++ gives the correct output.

the compiler can set b to whatever it thinks is most optimal for your situation, because when you define b you don’t specify a value. So, if you want it to always start as 0, set it to 0. On DevC++ it isn’t even guaranteed to give you 0 if you do other stuff in your program which cause memory blocks from the stack (memory dedicated to the process) to be reused.

1 Like