I never thought that such a question would arise, and nevertheless arose. The program is generally large, but did not want to work, constantly gave an error. Debugging, found in where the error occurs. If you simplify, you get the next situation:

void print(int); void print(int) { int k; printf("%d", k); } main() { int i; printf("vvedi i"); scanf("%d", &i); print(i); } 

He prints me some left value. Why, what is not so ?! Apparently this is elementary, but I won’t even consider it.

  • ps about the system ("pause") I know, I do not write them to save space, because the problem is not in them :) - Kollibry

3 answers 3

 void print (int k) { printf("%d",k); // и никаких локальных переменных } main () { int i; scanf("%d",&i); print(i); } 

Like so.

Something with formatting in the comments. I had to repeat in response.

    Sweet girl, think what your function does? After the call, it creates a local variable k, then the address of this variable is passed to the printf function. What do you think will be printed? That's right, the virtual address of this variable k itself is in decimal.

    • Thanks for the answer! but still, how can I make the value k be an argument? so that in main the function with the i parameter p. the value of k is transferred to printf ..... - Kollibry
    • without screaming - skegg
    • in my opinion, the author of the previous answer described everything very correctly. - skegg
    • 2
      guys who are you arguing with? they told you - pa-ra-dox, straustrup was wrong - Gorets
    • one
      Gorets, why so? > < - Kollibry

    In printf you need to pass values, and you pass the address. Generally try to replace

     void print(int) { int k; printf("%d", &k); } 

    on

     void print(int k) { printf("%d", k); } 
    • thanks, but not that. in code without & - Kollibry
    • By the way, it was with &. But this fact does not change. Nofate wrote everything correctly. - skegg