C Programming Part 1

I’ve been wanting to write a post about the basics of C programming language so here I am. We’ve heard it before from several or our nerdy colleagues – “Oh, I took a C programming class back in college, but I forgot all about it”. Well that’s because you obviously haven’t built many applications using C. To really know something in programming is to actually have done it.

I myself fall guilty of this – except I managed to salvage a C book at some random book donation. It was a super thick book, you just can’t imagine a C programming book being any other way. Its hardcover was in pastel yellow, inside was a pretty rough read. To be honest I only made it half way through the book, this was back in the mid 90s.

Fast forward to now – well we have the internet. We have the luxury of digital copies, audio books and youtube to provide us with everything a programmer could ever ask for. One thing I’ve noticed that hasn’t changed is the manner in which C is taught – it’s the same pattern.

1. Learn basic hardware – CPU, RAM
2. Learn C keywords – printf, scanf, data types
3. Learn basic C language and syntax
4. Apply these fundamental concepts to write simple programs.
5. Master the fundamentals and build something awesome.

My first programming language was PHP, though categorized as an interpreted high level language it’s still considered a programming language. Any set of instructions you give the computer is a programming language. I really like PHP.

So I wanted to go down the rabbit hole, or, I have decided too. I don’t run into programmers that program in C anymore. With the advent of some really cool hipster languages and frameworks, a lot of programmers these days end up really using frameworks and start deploying – hows that for high level programming. Hey I have nothing against that at all – I’ve done this many times myself in my consulting work. Frameworks are highly efficient, they get the job done.

I found some really good reliable learning material on the internet. And so I wanted to base this post on a youtube channel series I have been immersing myself into – it does a pretty good job of explaining the basics of C. This post will be based on my review of Introduction to Programming through ‘C’.

First off, I’m a big fan of finding truth. I’m unrelenting when it comes to finding reliable information I can deem valuable over a long period of time, a fundamental. It sounds like a tall order, but simply ordering something at your will is a luxury and many times superficial. To get to the truth, to get to something extremely valuable one must find where it all began. I actually had to prevent myself from getting deep into assembly and the CPU architecture for the time being.

Ok enough philosophy, on to the video and learning material.

Introduction to programming and programming languages: C Programming

  • A computer a general machine that can perform an computational task, you just need to give it a set of instructions, or a program.
  • A computer is nothing in itself without a program
  • System level programs manage the hardware resources of the computer
  • Application level programs perform perform tasks found on your desktop – ie web browser, text editor
  • If any of these programs can’t perform the task you’re looking for, you can write your own programs – hence the need for programmers
  • Binary is the language of computers, a number system that has only two digits – 0 or 1
  • We use the ten digit system, Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Computers are designed to understand binary because binary is really easy to simulate in the actual physical design of things in real hardware. This begs the question though – choosing an easy method leaves room for the possibility of alternative methods not ventured
  • A computer is an electrical device and it’s really easy to create the logic of zero and one in an electrical circuit.
  • For example if current is flowing through some wire, that is a 1. If a current is not flowing through, it’s a 0. In general 1 can correspond to something that exists, and 0 can correspond to something that doesn’t exist. Or 1 can represent true, or 0 can represent false.
  • 1 is also called set bit. 0 is called unset bit
  • A binary can only hold two possible values 0 or 1.
  • If we have 2 bits, you can have 4 possible values.
  • If we have 4 bits, we can have 8 possible values.
  • So if we have n bits, we can have possible values from 0 to 2n – 1
  • The central processing unit (or the CPU) is the core part of the computer responsible for executing all the instructions, or programs
  • Each instructions given to the CPU has to e a pattern of bits, a pattern of 1’s and 0’s

Your set of instructions, or program has to follow a CPU’s specifications or format

For instance, the specification to execute any logical or arithmetical operation will require 20-bits. To illustrate, the diagram below describes how this operation is stored in a 20-bit system.

Instruction in binary is often called Machine Language

  • Two CPU’s can have entirely different architecture and specifications
  • There was a time when programs were literally written in machine language, it was a tedious and error prone process.
  • Assembly language provided common instructions for operations and operands by using the keywords – “Add” or “Subtract”.
  • This is how the word assembler came about or what we commonly refer to as – compiler.
  • Assembly language needed to first go through an assembler which would translate instructions into machine language
  • Just like machine language, assembly language would vary from one machine from another, not easily portable. You may need to rewrite your program to a new set of specifications.
  • High level languages like C, C++, Java, Python made portability possible, because of abstraction

High Level Language (interpreted) vs Low Level Language (compiled)

  • Unlike compiled languages, interpreted languages do not generate executable code that can be executed seperately
  • Interpreted languages such as Python is processed on the fly and does not to be compiled

Dennis Richie, creator of C and Unix

  • C is still a very famous programming language. Java, C++ is derived from C.
  • Vocabulary, syntax, rules, and semantics is necessary to learn any new programming language

Stay tuned for part 2 of these series…