C Fundamentals

(By Dr. Leo Hu)


This handout is suitable for beginners to intermediate learners who study C systematically, and it can also be used as a reference tool for common knowledge points of C.

If you do not know C programming, please review C in 1 hour

This lecture introduces the elements of C programming language. You may quickly have an overview of the materials and refer back when coding with C. 

Please use this online C compiler IDE to test the programs in this handout and develop your own programs in learning. 

1.Tools for C programming 

When we prepare a C program, we must use an editor to write the program's source code. Since source code must be pure text (ASCII characters), the editor must be a pure text editor such as Notepad in Windows, and vi in Linux or Unix. 

Any program of source code written in a high-level programming language must be translated into machine code before it can be executed by a computer. There are two ways of translating source code into machine code: compiling and interpreting. 

Compiling is converting source code into machine code before the program is run. Interpreting is translating source code into machine code one line at a time as the program is running.  The tool for compiling is called a compiler, and the tool for interpreting is called an interpreter. 

C is a compiling language. Therefore, we need a C compiler to translate a C program into machine code. There are quite some C compilers available such as GCC (GNU Compiler Collection) and Clang. 

Since a C program source code may be written in multiple modules stored in a few files, and a program may need to use code in predefined libraries, a linker is usually needed to link the modules and libraries together to form an executable program. 

While we can use the independent editor, compiler, and linker in programming, we prefer to use an Integrated Development Environment (IDE) that has integrated the editor, the compiler, and the linker to work together. There are many IDEs available such as Code::Blocks, Eclipse, Microsoft Visual Studio, NetBeans, etc., and also many online IDEs such as programiz.com, CodeChef IDE, OnlineGDB, Repl.it, Paiza.io, and so on. 

In this lecture, we will use programiz.com for programming demos and hands-on practices. The programiz.com IDE in a browser looks like the figure below.