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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 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
 
*/

 



answered Jul 7, 2024 by avibootz
edited Jul 7, 2024 by avibootz

Related questions

1 answer 228 views
1 answer 133 views
1 answer 107 views
1 answer 105 views
1 answer 120 views
1 answer 138 views
7 answers 417 views
...