.c

What is a .c file?

C Source File · Code and data · Dennis Ritchie / Bell Labs · 1972

A .c file is C source code, the foundational systems language behind operating systems, embedded devices and countless tools. It is plain text compiled into fast native machine code.

Category
Code and data
Type
Plain text
Is a .c file safe to open? Caution. A .c file is program source. Compiling and running it executes its code, so review unfamiliar files first.

What is a .c file used for?

C gives direct control over memory and hardware, which is why Unix, Linux and much low-level software are written in it. A compiler such as GCC or Clang turns a .c file into an executable with a command like gcc file.c -o program.

Header files (.h) declare the functions and types that .c files share. The source is plain text and opens in any editor.

How to open a .c file

The .c format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .c file.

Windows

  • VS Code
  • Visual Studio
  • any text editor

macOS

  • VS Code
  • Xcode
  • any text editor

Linux

  • VS Code
  • vim
  • gcc / clang

How to convert a .c file

You can convert a .c file to exe (via a compiler), o (object file) using a conversion tool or the export menu of an app that opens it.

.c file signature (magic bytes)

Programs recognise a .c file by the bytes at the start of the file, not by its name. These are the signatures for C.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .c file?

A .c file is C source code, the foundational systems language behind operating systems, embedded devices and countless tools. It is plain text compiled into fast native machine code.

How do I compile a .c file?

Use a C compiler: gcc file.c -o program on Linux or Mac, then run ./program. On Windows, Visual Studio or MinGW does the same.

What is the difference between a .c and a .h file?

A .c file holds the actual code. A .h header declares the functions and types so other .c files can use them; headers are included, not compiled on their own.

How do I open a .c file?

Any text editor shows the source. An IDE like VS Code or Visual Studio adds highlighting, building and debugging.

Related formats

Sources

Details on this page were checked against authoritative references: