The C Language

C is one of the most powerful "modern" programming language, in that it allows direct access to memory and many "low level" computer operations. C source code is compiled into stand-a-lone executable programs. C is sometimes criticized because it assumes the "programmer is always right" and allows many "questionable" programming practices.

The C Programming Language

C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.

Yet, with great power comes great responsibility. C will not coddle you (okay, raise your hand if you think Matlab was coddling... well compared to C it was very generous to you). C will require your syntax to be even more perfect than Matlab. C will make you define every variable with a Type, and not let you ever change these (in a given program). C will assume you are a master of everything you do.

Further, C is a very basic language. There are no frills, no GUIs, no Matrix processing abilities, very little file I/O support, etc. (Note: to be honest, all of these things have been written in C and are available as libraries, but the core C language is in some sense, bare boned.)

Then, why do we use C?

  1. It was (and still is in some circumstances) the language of choice in Operating System Development (including all of Unix).

  2. It allows you direct control over the very low level aspects of the computer.

  3. Many legacy programs are written in C.

  4. Most of the things you learn with C will be directly transferable to future programming languages.

  5. Programs that are created with C run very quickly.

  6. C has a syntax (and some semantics) very close to Matlab, making the transition easy (okay, easier...).

  7. The programs you create in C will run "standalone". All of the programs we wrote in Matlab, need Matlab in order to work, and if you don't have access to Matlab, you are out of luck. C programs, once compiled into "executables", can be transferred to other (similar) machines, and run without the need for the source code.

  8. Many of the codes you will use in your future work/studies will have been written in C. You should at the least, be able to read them. And hopefully, you will be able to maintain, modify, and update them.

Parts of a C program

  1. #include statements (preprocessor directives)
  2. reserved words : (e.g., int, double, return, main, include, etc.)
  3. variables : (similar to Matlab)
  4. builtin functions (library functions) (printf, ...)
  5. {} ( similar to Matlab start and end of functions)
  6. main function
  7. comments : (// single line, /* .... */ multiple line

Sample C Program

The following is a "Design Pattern" for any basic C program:

 #include <stdio.h>  // tell C about printf

 int                      // return value of main function
 main()                   // where the program begins

   printf("hello world\n");

   return 0;              // exit status of main program (could be any number
			  // that we agree means the program is finished)

Programming Cycle in C

  1. Think about what program is supposed to do.
  2. Edit Program (comment program and then write code)
  3. Save Program
  4. Compile Program
  5. Fix Syntax Errors (Go back to Think above)
  6. Run/Test Program
  7. Fix Logic Errors (Go back to Think above)
  8. Run Program and Redirect Data into Diary File


See also:

  1. Compiling C Programs
  2. Debugging Programs

Back to Topics List