Download presentation
Presentation is loading. Please wait.
1
Scope and Casting
2
Scope Region of the program where a particular name can be referenced Formal parameters and local variables –can be accessed from within the function where they are declared Global variables –can be accessed from any function defined after the declaration –take care when using globals since any function can modify
3
Example #include int total; int main(void) { total = 0; add(30); printf(total); return (0); } void add(int num_to_add) { total += num_to_add; }
4
Integer Qualifiers int –-32,767 – 32,767 unsigned int –0 – 65,535 long –-2,147,483,647 - +2,147,483,647 unsigned long –0 – 4,294,967,295
5
Numerical Inaccuracies Representational Error –1/3 (0.33333…) – will result in round-off error small num * small num = number too small to represent –arithmetic underflow large num * large num = number too large to represent –arithmetic overflow
6
Automatic Conversion int + double –int converted to double –result is double double = int/int –expression evaluated –result converted to double int = double * double –expression evaluated –result converted to int
7
Casting int a=5, b=2; double x = a/b;
8
Casting int a=5, b=2; double x = a/b; //x is 2 Cast a or b (or both) to a double double x = (double)a/(double)b; double x = (double)(a/b); //x is 2
9
ASCII Code What is ASCII code? –American Standard Code for Information Interchange –all characters have an integer value –characters can be compared via relational operators –lowercase: a-z maps to 97-122 ASCII –uppercase A-Z maps to 65 – 90 ASCII
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.