C Data Types and Variable
Definition Data types are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them Example: Integer, float, character Before using variable it should be declared along with its datatype. Variable declaration syntax: Datatype variable_name
Static vs. Dynamic Typing First, what does strongly typed mean? Prevents invalid operations on a type Statically typed: strongly typed and type checks can be performed at compile time Ada, Pascal: almost all type checking done at compile time, with just a few exceptions C, C++, Java, Ocaml Dynamically typed: type checking is delayed until run time Scheme, Smalltalk, Perl
Types: Primitive Derived User defined Void
Basic Datatype Size of these types on CLEAR machines: Only really four basic types: char int (short, long, long long, unsigned) float double Size of these types on CLEAR machines: Size Varies from machine to machine
All datatype
Assignment A variable can be given value by means of assignment Assignment operator (=) is used for assignment Example: int x; x=5;
Initialization Values are NOT initialized during declaration by default in c If not initialized it may contain garbage value So better to initilialize during declaration Ex: int x=0; float product=1;
Display value of variable printf() function can be used to display value of variable Format specifier is compulsory to use Example printf(“value of x is %d”, x); printf(“y=%f”,y);
Getting value from user Commonly used function to get value for use is scanf()