0
#include <stdio.h>
int main(void)
{
    printf("ass");
    return 0;

}

A code is written without errors, the program is compiled without problems, but at her opening she takes off without errors, id est simply closed It is necessary for me that exe was started

hvck1337
  • 1
  • 1

1 Answers1

0

code written without errors (...)

No, not exactly. You can omit return value of printf function but actually it's header is a little different. Not to mention that some people would scold usage of C functions when C++ tag is given (use streams).

Why shouldn't You use printf without format string?

http://www.cprogramming.com/tips/tip/do-not-use-printf-without-percent-s-to-print-a-string

@Christian Hackl noticed in comment that it's quite safe to pass that particular string literal to printf, but consider what happens with one that has percent character [%], used inside printf https://stackoverflow.com/a/31293816/4476122

Now, program closes, and if You didn't see any output - word You so cleverly selected to share publicly with us - You might want to read about buffering.

Community
  • 1
  • 1
JustMe
  • 710
  • 4
  • 16
  • Are you saying that the OP should check the return value of `printf` for errors? That seems like a lot of overkill. – Christian Hackl Mar 18 '17 at 12:50
  • No, I wrote that OP can omit (ignore) it. But `printf ("string")` is wrong, `printf ("%s\n", "string")` is ok – JustMe Mar 18 '17 at 12:52
  • That's a half-truth, I'm afraid. See http://stackoverflow.com/questions/31290850/why-is-printf-with-a-single-argument-without-conversion-specifiers-deprecated for the whole story. Of course, as you are correctly saying, the OP should use `std::cout` anyway. – Christian Hackl Mar 18 '17 at 12:55
  • True, string literals will usually get placed in RO memory and in this simple example as there are no other stack arguments, except for stdin environment variables, but still... maybe I was just being picky about "code written without errors". Although You made me think do `main(void)` gets env, and argv[0] at all...thanks :) – JustMe Mar 18 '17 at 13:00