Skip to content

C Programming Language

Objective

At the end of this chapter, you should be able to read, write, compile and run simple C programs with the following features:

  • Input (scanf) with different data types including: int, float, double and char.
  • Output (printf) with different data types including: int, float, double and char.
  • Basic data types including: int, float, double and char.
  • Simple computations using:
    • Selection: if and switch-case
    • Repetition: while, do while and for

Assumptions

This note assumes that you have taken either CS1010, CS1101, or their variants. The two most common programming languages used in those modules are Python and JavaScript. As such, most of the comparison with C language will be from those two languages.

Introduction

Dennis Ritchie

C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at Bell Telephone Lab for use with UNIX operating system. The name was chosen because it is a successor of the B programming language.

Due to its popularity, it was standardised in 1989 by ANSI and then in 1990 by International Organization for Standardization (ISO). The C89/C90 standards are also referred to as the ANSI C standard.

von Neumann Architecture

von Neumann architecture is a computer architecture first described by John von Neumann in 1945. It has three main components:

ALU

  1. Central Processing Unit (CPU)
  2. Memory Unit
  3. I/O Devices

One of the crucial feature of the von Neumann architecture is the memory unit stores both program and data! This allows for the later development of compiler which takes in a program as if it is a data.

Olivier Danvy

"One man's program is another program data."

Additionally, the CPU are composed of:

  • Registers
  • A control unit containing an instruction register and program counter
  • An arithmetic/logic unit (ALU)

In short, the von Neumann architecture is the architecture of modern computer.