mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-04-06 09:05:21 +05:30
C: add static-const-variable.c
This commit is contained in:
parent
a4912b3671
commit
2517537ee9
38
c-programming/experiments/static-const-variable.c
Normal file
38
c-programming/experiments/static-const-variable.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* static-vs-const-variable.c
|
||||
*
|
||||
* Author: Intel A80486DX2-66
|
||||
* License: Creative Commons Zero 1.0 Universal or Unlicense
|
||||
* SPDX-License-Identifier: CC0-1.0 OR Unlicense
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.1415926535897932384626433832795028841971693993751058209749445922
|
||||
#endif
|
||||
|
||||
uint16_t frequently_called(uint8_t i);
|
||||
|
||||
uint16_t frequently_called(uint8_t i) {
|
||||
static uint16_t variable_1 = 2;
|
||||
const uint16_t variable_2 =
|
||||
(uint16_t) (
|
||||
(pow(10, floor(log10(M_PI))) + pow(10, ceil(log10(M_PI)))) / 2
|
||||
);
|
||||
static const uint16_t variable_3 = 3;
|
||||
|
||||
return variable_1 * variable_2 * variable_3 * i;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
for (uint8_t i = 1; i <= 16; i++) {
|
||||
printf("f(%02" PRIu8 ") = %" PRIu16 "\n", i, frequently_called(i));
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user