Floating point literals can have suffix to avoid ambiguities in functions calls
name | size (bits/bytes) | suffix |
---|---|---|
float | 32/4 | f |
double | 64/8 | |
long double | 80/10 | L |
If no suffix specified for literal, double
type used.
float width = 1.15;
float price = 1.0f;
long double frequency = 1.0L;
double temp = 0.0;
In C
language you can do this
int a = 5;
switch(a) {
case 0:
printf("Zero\n");
break;
case 5:
printf("Five\n");
break;
default:
printf("Another variant\n");
}
Seems not so pretty, but it's better to use switch-case
instead of if
, when you want to check, for example, which key was pressed in your videogame
switch(key) {
UP:
move_hero_up(hero);
break;
DOWN:
move_hero_down(hero);
break;
default:
hero_stay(hero);
}
Post increment like i++
means, that addition will be performed after other operations in current expression
int i = 5;
printf("%d\n", i++); // Will print 5
printf("%d\n", i); // Will print 6
Pre increment written ad ++i
will increment before expression evaluation
int i = 5;
printf("%d\n", ++i); // Will print 6
printf("%d\n", i); // Will print 6
Also you may want to create an array of numbers
float steps[3] = {1.0, 2.0, 5.5};
You can fill not all values at one time and take care of them later
int numbers[5] = {0, -14, 17};
numbers[4] = 16;
numbers[3] = 5;
Following example will change value of variable
int a = 5;
change_me(&a, 3);
printf("%d\n", a); // will print 8