Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Teach Your Child To Read

Disclosure: My content contains affiliate links.

31,649 questions

41,702 answers

573 users

How to check the data type of a variable in C

1 Answer

0 votes
#include <stdio.h>
#include <stdint.h>
 
// C11
 
#define vartype(x) _Generic((x), \
    char: "char", \
    int: "int", \
    double: "double", \
    uint32_t: "uint32_t", \
    default: "unknown" \
)
 
int main()
{
    char v_char = 'a';
    int v_int = 90;
    uint32_t v_uint32_t = 9727133;
    double v_double = 672.903;
     
    printf("v_char is %s\n", vartype(v_char));
    printf("v_int is %s\n", vartype(v_int));
    printf("v_uint32_t is %s\n", vartype(v_uint32_t));
    printf("v_double is %s\n", vartype(v_double));
     
    return 0;
}
 
 
 
/*
run:
 
v_char is char
v_int is int
v_uint32_t is uint32_t
v_double is double
 
*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 7 by avibootz
edited Jul 7 by avibootz

Related questions

1 answer 150 views
1 answer 5 views
1 answer 6 views
1 answer 6 views
1 answer 7 views
...