zaro

What is a out in C?

Published in C Compilation 2 mins read

a.out is the default name for executable files created by C compilers and linkers when you don't specify a different output file name.

Understanding a.out

Although historically a.out referred to a specific executable file format, the term is now more commonly used as the default file name for executables, regardless of the actual format.

  • Default Output: When you compile a C program (e.g., gcc myprogram.c), and you don't use the -o option to specify an output file name, the compiler typically names the resulting executable a.out.

  • Not Always the a.out Format: The resulting executable may not actually be in the a.out format, especially on modern systems. It could be in ELF (Executable and Linkable Format) or Mach-O format, depending on the operating system and compiler. The name a.out persists as a convention.

Example

Let's say you have a simple C program called hello.c:

#include <stdio.h>

int main() {
  printf("Hello, world!\n");
  return 0;
}

If you compile it using:

gcc hello.c

An executable file named a.out will be created in the same directory. You can then run it with:

./a.out

This will print "Hello, world!" to your console.

If you want to name your executable something different, you can use the -o option:

gcc hello.c -o hello

This will create an executable named hello, which you can run with ./hello.

Key Takeaways

  • a.out is the default output file name.
  • The content may not literally be in the a.out format.
  • You can change the output file name using the -o option during compilation.