Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,765 questions

10,845 answers

573 users

How to check whether a variable is int or const int in C

1 Answer

0 votes
#include <stdio.h> 

#define is_int_const_int(n) _Generic((&n),  \
            const int *: "const int",       \
            int *:       "int",             \
            default:     "other type")

int main(void)
{
    const int ci = 99;
    int i = 10;
    float f = 3.14;
    
    printf("ci is: %s\n", is_int_const_int(ci));
    printf("i is: %s\n", is_int_const_int(i));
    printf("f is: %s\n", is_int_const_int(f));
    
    return 0;
}
    
/*
run:
 
ci is: const int
i is: int
f is: other type

*/

 




answered Aug 21, 2017 by avibootz
...