Skip to content

Instantly share code, notes, and snippets.

@YulongNiu
Created October 24, 2017 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YulongNiu/f12d40a538e0c886b3ae3c74cb5c4ace to your computer and use it in GitHub Desktop.
Save YulongNiu/f12d40a538e0c886b3ae3c74cb5c4ace to your computer and use it in GitHub Desktop.
Test the maximum and minimum int value in C99
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main() {
int a = INT_MIN;
int b = INT_MAX;
double c = DBL_MIN;
printf("min is %d and max is %d \n", a, b);
printf("min positive double is %ef \n", c);
// test cross limits
for (int i = 0; i < 10; ++i) {
printf("test %d cross min is %d and cross max is %d \n", i, a - 1, b + 1);
}
return 0;
}
@felixlyd
Copy link

I tested it with codes:

for (int i = 0; i < 10; ++i) {
        printf("test %d cross min is %d and cross max is %d \n", i, a - 1, b + 1);
        a = a - 1;
        b = b - 1;
    }

and I get something different

@YulongNiu
Copy link
Author

@Godinlove Can you paste your results here and also you gcc version?

@felixlyd
Copy link

gcc 4:6.3.0-2ubu amd64 GNU C compiler

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment