1

When I run

$ gcc hello.c
$ ./a
Hello, World. 

I don't know what ./a exactly indicates.

What is it? What does it stand for?

If you know the meaning of it, I'd really appreciate that you would share.

Jens
  • 69,818
  • 15
  • 125
  • 179
Jeon JI No
  • 25
  • 6

2 Answers2

2

./ is the current directory when using a Unix-like shell (like bash.) The name of the executable GCC produces is a.exe.

So to run the produced executable, you need to specify the path to to it, in this case "the current directory", which is ./, and the name of the executable, which is a.exe. Since you can omit the .exe when running executables on Windows, instead of ./a.exe you can just run it with ./a.

If you were to use the Windows command-line shell (like cmd.exe or PowerShell) you would instead just type a, because the current directory (.\ in this case, Windows uses \ instead of / for the directory separator character) is searched for executables by default. Unix shells do not, which is why you need ./.

If you want to give the produced executable a different name, for example hello.exe, you can:

gcc hello.c -o hello.exe

You would then run that with:

./hello

or:

./hello.exe
Nikos C.
  • 50,738
  • 9
  • 71
  • 96
1

.a is the standard/default output of the compiled program, when no output name is provided.

When you've compiled C program and given no name to the output file, gcc will automatically set the output file name as a.

The file name is overwritten for the last compiled C program, when no output name is provided.

This standard is same in both Unix and Windows.

To set name for the output program, Use -o argument followed by the output name sum_program

gcc sum_program.c -o sum_program

Depending on the library use, and other linkers, additional arguments like -o can be added for compilation.

Susobhan Das
  • 247
  • 2
  • 17