1

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" ?
user3704652
  • 303
  • 4
  • 6
  • 16

3 Answers3

8

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.

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
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.

Spectorsky
  • 608
  • 4
  • 23
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

Mukul Kumar
  • 315
  • 1
  • 5
  • 16
  • 1
    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). – starriet Aug 15 '22 at 03:59