Objective-C: Variables
A variable it’s a data type and can be composed by letters, numbers and underscore character.
Type:
- char: 1 byte(octet)
- int
- float: single precision floating point value
- double: double precision floating point value
- void: absence of type
- bool: true or false – 1 byte
Variable definition:
Syntax: type variable_name;
Example:
int i,j,k;
char c, ch;
float f, money;
double d;
Code:
#import <Foundation/Foundation.h> // Variable declaration: extern int a, b; extern int c; extern float f; int main () { /* variable definition: */ int a, b; int c; float f; /* actual initialization */ a = 10; b = 20; c = a + b; NSLog(@"value of c : %d \n", c); f = 70.0/3.0; NSLog(@"value of f : %f \n", f); return 0; }
341,926 total views, 1 views today