Variables

You are currently browsing articles tagged Variables.

int x;
int y = 5;
int z = x;

variables = expression/assignment

Area – length * width <- Assignment Statement

int feet=6;
int inches = feet * 12

printf(“%d feet = %d inches\n”,feet, inches)

%f = floating point
%d = decimal system based interger
%i = interger
%h = hex integer

Declaration
int = feet

Assignment
feet = 6

Tags:

Include Files
- Pull what is necessary from included library’s and inserts into Binary

Standard Libraries
- Math and Standard Operations

The Preprocessor (More on this in CSE 230)
- Strips our Comments
- Makes substitutions for named constants
- insert definition of included function files (Reserves space for them)

Every C Program must have a main function
int main (void)

  • Execution begins and ends with the main function
  • Program Statements are executed sequentially
  • Execution begins at first statement of main
  • ( ) are used to specific function parameters
  • { } enclose the body, are used to group statements
  • If you do not declare int main you do not need to end with return 0;
  • \n means “go to the next line”
  • \ backslash key is an escape character
  • \t means tab
  • return 0; – Signals successful end of your program to the operating system
  • Many functions return values, ie: Mathematical functions

Program Structure

  1. Preprocessor directives
    1. #include-d files
    2. Other definitions/Declarations
  2. Supporting functions
  3. Main functions

Variables are named blocks of memory
Intergers
Regular int = 4 bytes
Short int = 2 bytes

Floating Points
Float = 4 bytes (standard accuracy, 8 digits after decimal)
Double = 8 bytes (better accuracy, more decimals)

Char – 1 byte

Every memory block has a # and your var is assigned a # (by Preprocessor?)

Tags: , , ,