Began to study C. Elementary program:

#include <stdio.h> #include <math.h> int main(void) { float a; float b; scanf("%f", a); scanf("%f", b); printf("Result: %f", pow(a, b)); } 

Exit status -1 . Why doesn't it work as planned? Why is there no error in the output? What to fix?

  • What is "Exit status -1"? Where did you get this "Exit status"? - AnT
  • @AnT console output - Don2Quixote

2 answers 2

Briefly:

 scanf("%f", &a); scanf("%f", &b); 

You must pass the address of the variable where to write the read value. You write to a random address, into which the value is converted from the variable a (and then b , if it comes to this and the program does not crash earlier).

But I can not believe that it was not written in capital letters in the textbook that you read - that you need to pass the address of the variable. And that the compiler did not warn you about a possible problem ...

    Formally, your mistake is a runtime error. Therefore, in any "conclusion" it should not be. No one except you can place a runtime error in the "output". However, most modern compilers will still notice this common mistake and report at least a warning about it. Maybe you just ignored the diagnostic messages of the compiler?

    Must be

     scanf("%f", &a);