Discussion

C as a Programming Language:

  • Programming as logic
  • Language as grammar and syntax
  • Procedural
  • Modular
  • Abstraction/Hiding
  • Object-Oriented
  • C++: Parametrization or Generic Programming

Building:

  • Generating an executable from code
  • Concept of Makefile

Compiling:

  • Preprocessing – cpp
  • Compiling – gcc
  • Some important flags (-o, -c, -Wall, -L, -I, -l, -g, -O, -D, -Wl,)
  • Cross compiling

Directives and Include:

  • #include
  • #define
  • #ifdef
  • Include guards
  • What's in the include?
  • Include path “”, <>

General Guidelines

  • Maintainability/Readability
  • Flexibility/Scalability – Growth and Reduction
  • Usability
  • Re-usability of Code

Empty Program

  • Every statement ends with ;
  • Space insensitive
  • {} scopes
  • A brief intro to functions
  • main

Data Types

  • Primitive/Built-in data type controls:
  • Typical types
    • double, float
    • int, short, long, long long
    • unsigned, unsigned short, unsigned long, unsigned long long
    • char, unsigned char – ASCII
  • typedef (architecture example)

Variables

  • Data Type (Domain)
  • Scope – Variables on stack
  • Declaration
  • Global variables
  • Qualifiers
    • static
    • extern

Data Represenation

  • Writing constants
  • Chars
  • printf
  • scanf

Operators


(type)  Cast Operator
[ ]  Array Subscript
a.b  a Member of b
a->b a Member by pointer b
}
  • Unary (pre/post++, !, ~, &, *)

++a Prefix Increment
a++ Postfix Increment
!   Not
&   Address-of 
*   Indirection of (used mainly with Pointers)
~   

  • Arithmetic (*,/,%,+,-)
  • Bitwise (>>,<<,&,^,|)


==
    is equal to
!=
    is not equal to
>
    is greater than
<
    is less than
>=
    is greater than or equal to
<=
    is less than or equal to 
  • Logical (&&, ||)

&&  Logical AND
    is logical AND same meaning as the AND operator
||  Logical OR
    is logical OR same meaning as the OR operator
  • Conditional (? :)

Precedence

  • Who gets processed First?
  • Primary
  • Unary (Right associative)

Casting

  • Explicit cast
  • Implicit cast

Code Example


//Declaration
int x; char c = 'k';
int x, y;



//Explicit Casting
char x = 'a'; int y = (int) x;
int x = 5; char y = (char) x;



// Implicit cast
double a, b, c; int x; c = a*b + x;
x = a*b + c;