Last active
December 26, 2021 00:46
-
-
Save opsJson/83d08d29e4eec311ff929c5f04285e19 to your computer and use it in GitHub Desktop.
Easily gets the type of a variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
#define typeof(x) \ | |
(((x == 0) ? (x = 0.00000000001) : (x)) / INT_MAX == 0) \ | |
? ("0cs0i0000"[sizeof(x)]) \ | |
: ("0000f000d"[sizeof(x)]) | |
int main() { | |
char c; | |
int i; | |
float f; | |
double d; | |
short int s; | |
printf("char: %c\n", typeof(c)); | |
printf("int: %c\n", typeof(i)); | |
printf("float: %c\n", typeof(f)); | |
printf("double: %c\n", typeof(d)); | |
printf("short int: %c\n", typeof(s)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment