lesson 6 mattover c
[[lesson_6_mattover_c]] last edit on Aug 9, 2005 2:29 AM by rescued_by_c

[user02@FC4 Lesson06]$ cat -n mathover.c
   1  #include <stdio.h>
   2
   3  int main(void)
   4  {
   5     int result;
   6
   7     result = 200 * 300;
   8
   9     printf("200 * 300 = %d\n", result);
  10
  11     return 0;
  12  }
[user02@FC4 Lesson06]$ gcc -o mathover mathover.c
[user02@FC4 Lesson06]$ ./mathover
200 * 300 = 60000



[user02@FC4 Lesson06]$ cat -n mathover2.c
   1  #include <stdio.h>
   2
   3  int main(void)
   4  {
   5     short result;
   6
   7     result = 200 * 300;
   8
   9     printf("200 * 300 = %d\n", result);
  10
  11     return 0;
  12  }
[user02@FC4 Lesson06]$ gcc -o mathover2 mathover2.c
[user02@FC4 Lesson06]$ ./mathover2
200 * 300 = -5536



[user02@FC4 Lesson06]$ cat -n mathover3.c
   1  #include <stdio.h>
   2
   3  int main(void)
   4  {
   5     int result;
   6
   7     result = 200000 * 300000;
   8
   9     printf("200000 * 300000 = %d\n", result);
  10
  11     return 0;
  12  }
[user02@FC4 Lesson06]$ gcc -o mathover3 mathover3.c
mathover3.c: In function ?emain?f:
mathover3.c:7: warning: integer overflow in expression
[user02@FC4 Lesson06]$ ./mathover3
200000 * 300000 = -129542144
[user02@FC4 Lesson06]$