Introduction to C

A Brief History

C is a low programming language that has been around since 1972. It was developed by a man named Dennis M. Ritchie, and first used on the DEC PDP-11 computer (which was first produced in 1968). One of the first publicly available descriptions of C was released by Ritchie and his colleague, Brian Kernighan, back in 1978. This description was known as the K&R Standard. The K&R Standard is a bracketing style where braces are left out of statements if they are not required.

An IF statement that follows the K&R Standard.

Why Use C?

C is commonly used as a system development language, due to its code running nearly as fast as the code written in assembly language. Since C is a low level programming language, it is possible to generate code that can run before filesystems, virtual memory, and processes. For these reasons, C is commonly used to create operating systems for hardware such as printers, computers, phones, etc.

Who Uses C?

The following examples of programming languages, operating systems , and games/game engines are all fully or partially based upon C:

C is fully or partially used to implement all the items in the table.

Differences between C and JAVA

C and JAVA contain a lot of similarities. If you can understand how one of these languages work, the other one becomes easier to learn. However, there are quite a few differences between the two languages. Here is only a few:

  • C is a procedural language, JAVA is an object oriented language.
  • C is a low level language, JAVA is a high level language.
  • C requires the creation of pointers to reference objects, JAVA does not.
  • Memory in C is managed by the user, JAVA uses the garbage collector.
  • JAVA supports method overloading, C does not support function overloading.
  • JAVA contains exception handling, C does not (however there are ways to deal with errors).

Makeup of a C Program

C programs typically consist of five main components. These components are:

  • Preprocessor Commands: Code that transforms the program prior to compilation. Ex. #include <stdio.h>
  • Functions: A group of statements that perform a task.
  • Variables: Named locations in the memory that hold a value.
  • Statements and Expressions: Code that makes up the body of functions.
  • Comments: Helpful text inside a program to assist in readability.

Simple C Program

The Hello, World! program is a simple (and cliche) application that will simply print out the phrase “Hello, World!” to the console. In C, this is what the code would look like:

The Hello, World! source code.

As we can see from this code, there is a preprocessor command to include the library stdio.h. This allows the programmer to include basic input and output functions in their application, such as printf (as used in the Hello,World! example).

When a C program is executed, the first function that always runs is the main() function. The return value for this function is an int data type with a value of 0 or 1 to indicate if the program has run successfully (shown in the “return 0;” statement). 0 means the program ran successfully, 1 means the program ran with errors.

The result from running this program successfully will be “Hello, World!” printed to the console.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Firebase Crashlytics: How to debug crashes without uploading dsym file

Building a Kill Switch in SBOL

Drop the bastion in the clouds (AWS, Azure (kinda), and GCP)

Why “no code operations” is the next big job in tech

After solved 1000 leetcode medium level I found these patterns — Dynamic Programming

Perforis™ O5 Methodology for Microsoft Dynamics 365 Support

Protect your application on kubernetes with authelia

Facing my fears of being a first time Open Source contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Rose

Matthew Rose

More from Medium

Meaningful Code Writing…..

Why you need DateTimeOffset?

C programming