Lecture 2: C basics

Today, we start to learn about the C programming language.

Hardware and software

video

slides

Optional reading: chapter 1

Key ideas:

  • Hardware: memory cells, bits, bytes, memory addresses, RAM vs. ROM, CPU
  • Software: operating systems, application software
  • Computer languages: machine language, assembly language, high level languages
  • Compiling your C programs: source file, compiler, object file, linker, executable file

C overview

video 1

video 2

Optional reading: chapter 2.1-2.6

Key ideas:

  • Parts of a C program: preprocessor directives (#include and #define), main function, declarations vs executable statements
  • Variable declarations and data types
  • Use gcc -o [executable_filename] -Wall [c_filename] to compile your program and ./[executable_filename] to run
  • Assignment statements
  • Comments and whitespace
  • printf and scanf: placeholders (%), float formating
  • Newline and tab: \n and \t
  • Arithmetic expressions

Programming errors

video

Optional reading: chapter 2.8

Key ideas:

  • Four different types of errors: syntax errors, runtime errors, undetected errors, and logic errors