C is a pro­gram­ming language that’s been essential since the 1970s. It forms the found­a­tion of modern operating systems, making it an integral part of pro­gram­mers’ daily lives.

Primary uses for C

It’s no wonder that the in­flu­en­tial pro­gram­ming language C is used in a number of areas and is one of the most common languages in existence. Since its de­vel­op­ment in the 1970s, it’s been winning over pro­gram­mers from various areas, thanks to its re­mark­able speed. It’s also a popular choice for people who want to learn pro­gram­ming.

It’s no surprise that the primary use for C is in system pro­gram­ming, given how close it is to the hardware. The goal of C is to offer as exact an ab­strac­tion as possible from the native assembler code. The port­ab­il­ity of the language as well as the fact that it can interact directly with hardware makes it an excellent choice for pro­gram­ming drivers or even entire operating systems.

Compilers, the libraries of other pro­gram­ming languages, and entire higher-level pro­gram­ming languages are based on C and benefit from the speed and small file size of C programs.

Pros and cons of C

The pro­gram­ming language C is a popular for a reason. One of its major ad­vant­ages is the fast execution speed of programs compiled in C. The fact that C code is highly portable and can be used in a variety of operating systems is another good reason for using it. Another benefit of C is that it contains con­structs used in other pro­gram­ming languages, meaning that if you’re competent in C you should be able to switch over to other languages pretty easily.

But if you’re a beginner, pro­gram­ming with C can have its drawbacks. Its closeness to the hardware means that errors you make in code can lead to a mess in your system. And the learning curve for C is re­l­at­ively high, in part since it’s not object oriented.

Syntax of C

The syntax of a pro­gram­ming language is the set of rules you have to follow in order to write ex­ecut­able source code. Just like every other pro­gram­ming language, C has some syntactic idio­syn­crasies that pro­gram­mers should be aware of.

  • Semi­colons: Every statement ends with a semicolon in C, re­gard­less of whether you’re calling a function or declaring a variable.
  • Curly brackets: Sets of state­ments are marked with an opening and closing curly bracket in C. This means that in­dent­a­tion isn’t necessary, unlike in other pro­gram­ming languages, though it does aid sig­ni­fic­antly in making your code more readable.
  • In­teg­rat­ing libraries: If you want to integrate a library in order to used pre-defined functions, you can use an include statement:
#include <stdlib.h></stdlib.h>
  • The main function: The main function serves as the start and end of a program. Every C program needs to contain a main function.
#include <stdio.h></stdio.h>
// This is where the main function begins. It contains the string “Hello world!”.
int main(void) {
	printf(“Hello world!“);
}
  • Com­ment­ing: Use two slashes for single-line comments. For multi-line comments, use the notation “/* Comment */“.

Which pro­gram­ming languages are based on C?

C forms the found­a­tion of a number of other pro­gram­ming languages, most of which are used for system and software de­vel­op­ment. C++ and C# are based directly on C. Unlike C, those two im­per­at­ive languages are object oriented, meaning that they provide a different range of features than C. The object-oriented language Java is also based on C and has very similar syntax.

Some pro­gram­ming languages used for web de­vel­op­ment are also based on C. One popular example is the script language PHP, which forms the found­a­tion for many web apps like WordPress. Javas­Script, the language used for pro­gram­ming in­ter­act­ive websites, is also based on C.

Dif­fer­ences between C, C#, and C++

The similar names of the pro­gram­ming languages C, C++, and C# can lead to confusion. The dif­fer­ences between the languages, however, are clear. The three languages follow distinct pro­gram­ming paradigms: While C is used for im­per­at­ive pro­gram­ming, C# and C++ are object-oriented languages.

What is the dif­fer­ence between C++ and C# then? This is where it gets a bit more difficult. C is a subset of C++, meaning that every program written in C can also be written in C++. C++ contains a number of ex­ten­sions, like object ori­ent­a­tion, that C doesn’t have.

C# (which is sometimes called C++++ is also object oriented but is easier to learn than C++. This is because managing memory is simpler with C#. Ad­di­tion­ally, C# was ori­gin­ally designed with Windows rather than Linux in mind and is based on the .NET-Framework, meaning that users need to have .NET runtime installed. C# is suitable for all kinds of programs but is mostly used for pro­gram­ming games. It’s less well suited to pro­gram­ming close to the hardware.

The first steps in learning C

If you’ve decided to learn C, you’ll need a compiler for turning your code into ex­ecut­able programs. On Linux, you’ll find a pre­in­stalled compiler and on Windows you can easily download one. One popular solution for Windows is MinGW, which enables you to use the Linux C compiler GCC on both operating systems.

If you’re looking to write large, complex programs, you might want to look into an in­teg­rated de­vel­op­ment en­vir­on­ment (IDE) for C pro­gram­ming. An IDE isn’t necessary, but it will help you with syntax high­light­ing and an in­teg­rated debugger. Which IDE you decide on is a question of taste. CLion is available for all operating systems and offers a number of useful features. Visual Studio for Windows and Xcode for MacOS also support C.

Tip

Want to learn C++? Take a look at our tutorial!

Go to Main Menu