2

When I compile below "hello_world.c" through cc hello_world.c,
it makes an 'a.exe' instead of 'a.out'

#include <stdio.h>

main()
{
    printf("hello, world\n");
}
  1. What is a difference between "a.out" and "a.exe" ?
  2. Why I get an "a.exe" instead of "a.out" ?
4
  • 1
    That depends of your compiler and it's settings. State the compiler and it's settings Commented Nov 19, 2017 at 13:39
  • 2
    Because executable files have a .exe extension on Windows, but not on other platforms.
    – interjay
    Commented Nov 19, 2017 at 13:42
  • I'm sorry but, how can i check the version of my compiler? I installed the visual studio 2015 on windows 10 and i compiled the code as "cc hello_world.c" Commented Nov 19, 2017 at 13:43
  • Read this: en.wikipedia.org/wiki/.exe
    – babon
    Commented Nov 19, 2017 at 13:48

3 Answers 3

9

That depends on your platform. For example gcc will produce .out on linux, and .exe on windows if you don't give it any additional parameters. (i.e. run cc / gcc "source").

You can force gcc to produce a .out on windows with gcc "source" -o "dest.out".

If your compiler outputs one extension by default (in your case it seems that .exe is the default which is perfectly OK for Windows), I would stick with it. No need to worry about not getting the other type.

2
  • The user is writing 'I installed the visual studio 2015 on windows 10 and i compiled the code as "cc hello_world.c"', so it was Windows....
    – Spectorsky
    Commented Nov 19, 2017 at 13:59
  • I modified the question. Thank you. Commented Nov 19, 2017 at 14:00
3

Binary executing files in Windows have extension exe. I am not sure about com-files supporting, but it is not our case. Extension out usually uses for writing a text protocol when some program is working. I could guess that it is your program itself, being launched, creates out-file. For more help, provide at least what program environment is used to compile your C-program.

2

a.out temporary file that is created after compilation of a c program is actually an Object Code for Unix-like operating systems. Object code is used for writing system calls which implements the code functionality and relocation information for linker to help it find the object code in memory(more info here).

Compiler compiles the code and writes a file known as object code and in linux/unix the file is known as a.out. This file can be further linked to definitions(OR more technically libraries) present in the operating system to form the executable image.

For example in Windows :
enter image description here

1
  • 2
    I didn't downvote, but your answer can be confusing because usually a.out is an executable, not an obj file. Normally .o is the result of compilation, before linking (object file). Commented Aug 15, 2022 at 3:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.