Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

How to code using the C programming language in Mac OS X

Lucy Hattersley | May 26, 2016
Mastering the C programming language - a classic code environment used to build software, apps, and whole operating systems - is a great skill, and Mac OS X makes it easy to learn. Here's how to get started

The C programming language has been around since the 1970s, but it has never gone out of style, and learning C is one of the best computer skills you can acquire. Mac OS X comes with C built into it, and Apple has used C while making every aspect of OS X and iOS.

Because C is such a popular language, it even forms the basis of many other programming languages, including two big names: C++ and Objective-C. And even though Apple is migrating from Objective-C to Swift, guess what languages Apple used to build Swift? Throughout the Swift code, you'll find C and C++ files.

How to learn C in Mac OS X: Why you should learn C in Mac OS X

You're almost sure never to use C professionally, but learning it is a rite of passage for programmers.

The C programming language has influenced many other languages. Learning C enables you to understand what's going inside a computer in general.

C is also a curious creature, in that it's a high-level language (these are the easy ones to understand), but with low-level elements (so-called because they are "close to the metal"). The C syntax is similar to many modern programming languages. However, you have to learn how to allocate memory, free up memory to prevent leaks and use memory addresses and pointers (memory blocks that point to other memory blocks). All of this memory management will most likely drive you to tears at some point, but it's superb for understanding what a programming language is doing.

This complexity is why C is used in courses such as Harvard's CS50: Introduction to Computer Science. More modern languages, like Python, take care of memory for you; which is better for day-to-day use, but not as good educationally.

How to learn C in Mac OS X: How to set up C in OS X

Learn to code using the C programming language on your Mac: Set up C in OS X

Like Python, it's easy to set up C in OS X. Mostly because it's already packaged in the system and you don't need to install anything.

Open terminal and enter clang --version. Clang is the compiler built by Apple to compile C and a bunch of other languages. We get Apple LLVM version 7.3.0 (clang-703.0.29) but whatever version you're using is good enough to compile beginner's code.

There are multiple standards for C, and the two you'll come across most are C99 and C11. As a newcomer, you don't need to worry too much about these, and you'll almost certainly learn C99 then discover the new features in C11.

 

1  2  3  Next Page 

Sign up for CIO Asia eNewsletters.