C
Topics
Pages
Content
Wikipedia excerpt:C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations
Key links
Uncategorized Links
-
The Development of the C Language
- Article on the Bell Labs site.
Tutorials
- What is C Programming Language? Basics, Introduction and History
- C language introduction
- C in 100 seconds
Overview
- C is a general-purpose language.
- History
- It is known for its high performance and control of low-level areas such as managing memory.
- C is not so beginner-friendly - you need verbose code compared with other languages, even to do something simple. Some alternatives are C++ or Java, or the more modern Go and Rust.
- However, the advantage is that gives a high degree of control which means you can optimize memory management at a low-level.
- Strongly and statically typed. You have to explicitly set the type (e.g. 32-bit signed integer) in most cases and objects cannot change type. The types are checked at compile time.
- You compile your scripts into binary executables specific to an OS. This makes it very portable - if a compiled binary is produced for each of Linux, Windows, and macOS, they can be distributed online and downloaded and run by anyone.
- By having the compile step, there is an initial cost in time. But then the compiled code can run much faster later than interpreted code such as in JavaScript, Ruby or Python.
- C has variables and functions.
- Memory is managed manually. There js no garbage collection. This gives more control for systems programming.
- There are no classes. There is no string type (though you can have an array of characters). There is no boolean - instead you use
0
for false and1
for true. - It makes use of pointers - a function can operate on a pointer of a variable and modify it in place, without making a copy of the value which would use extra memory.
- Extensions:
.c
- source code file..h
- header file. It may contain constants, function prototypes and external variable definitions..o
- compiled object file..so
- shared object file.
Implementation
Most programming language you come across such as Bash, Python or Java will be implemented in C.
For example, the commonly used version of Python known as CPython and can be found here GitHub as (python/cpython). That is Python implemented in C. You will see many files there written in C with .c
or .h
extensions. When you run Python code or import a builtin library, you might be running compiled C code directory or you might be running Python code which internally runs C code. Running C directly is typically much faster, as running Python code requires interpretation and compilation at runtime.
There are alternatives such as Jython implemented in Java and IronPython implemented in C#.
Help
Get help on the GNU C Compiler
$ man cc
$ info cc
$ cc --help
See also:
$ gcc
For C++ and C code:
$ g++