How to determine whether a variable is unsigned or not in C

1 Answer

0 votes
#include <stdio.h>

int main(void)
{
    unsigned int n = 30;

    if (n >= 0 && ~n >= 0) {
        puts("unsigned");
    }
    else {
        puts("signed");
    }


    int x = 30;

    if (x >= 0 && ~x >= 0) {
        puts("unsigned");
    }
    else {
        puts("signed");
    }

    return 0;
}




/*
run:

unsigned
signed

*/

 



answered Jul 12, 2023 by avibootz

Related questions

1 answer 124 views
2 answers 306 views
4 answers 245 views
8 answers 629 views
3 answers 244 views
3 answers 415 views
...