Exam 2 Review

Joseph Haugh

University of New Mexico

Review Topics

  • Basic syntax
  • Variable scope
  • Arrays
  • Pointers
  • Bitwise operators

Basic Syntax

  • C is case sensitive
  • Statements end with a semicolon
  • Blocks are enclosed in curly braces
  • Comments are enclosed in /* */ or //

Variable Scope

  • Variables are only accessible within the block they are declared in

Arrays

  • Arrays are a collection of elements

  • Arrays are zero-indexed

  • Arrays can be initialized using the following syntax:

    int array[] = {1, 2, 3, 4, 5};
  • Arrays are contiguous in memory

  • Arrays can be passed to functions

  • Arrays can be passed to functions as pointers

Pointers

  • Pointers are variables that store memory addresses
  • Pointers can be dereferenced using the * operator
  • Pointers can be used to access array elements
  • Pointers can be given the address of a variable using the & operator

Bitwise Operators

  • Bitwise operators are used to manipulate individual bits
  • The & operator performs a bitwise AND
  • The | operator performs a bitwise OR
  • The ^ operator performs a bitwise XOR
  • The ~ operator performs a bitwise NOT
  • The << operator performs a left shift
  • The >> operator performs a right shift
  • Bitwise operators can be used to set, clear, and toggle bits
  • Bitwise operators can be used to check if a bit is set or not