Difference between revisions of "C datatypes"
From Teknologisk videncenter
m (Created page with "=Int and long int= <source lang=c> #include <stdio.h> //Author: heth@mercantec.dk int main( void ) { int int_max,int_min; unsigned int uint_max; long int...") |
(No difference)
|
Revision as of 08:55, 22 May 2012
Int and long int
#include <stdio.h>
//Author: heth@mercantec.dk
int main( void ) {
int int_max,int_min;
unsigned int uint_max;
long int lint_max,lint_min;
unsigned long int ulint_max;
printf("Integer size = %i - long integer size = %i\n",
(int) sizeof(int_max), (int) sizeof(lint_max) );
printf("================= integer ================\n");
int_max = 0x7fffffff;
int_min = 0x80000000;
printf("int_max = %i og int_min = %i\n", int_max,int_min);
int_max++;
int_min--;
printf("int_max = %i og int_min = %i\n", int_max,int_min);
printf("=========== Unsigned integer =============\n");
uint_max = 0xffffffff;
printf("uint_max = %u\n" , uint_max);
uint_max++;
printf("uint_max = %u\n", uint_max);
printf("==============Long integer ===============\n");
lint_max = 0x7fffffffffffffff;
lint_min = 0x8000000000000000;
printf("lint_max = %li og lint_min = %li\n", lint_max,lint_min);
lint_max++;
lint_min--;
printf("lint_max = %li og lint_min = %li\n", lint_max,lint_min);
printf("=========== Unsigned integer =============\n");
ulint_max = 0xffffffffffffffff;
printf("ulint_max = %lu\n" , ulint_max);
ulint_max++;
printf("ulint_max = %lu\n", ulint_max);
}
Compiling and running
heth@mars:~/bin$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.5-15ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.5-15ubuntu1)
heth@mars:~/bin$ clear
heth@mars:~/bin$ gcc -V
gcc: '-V' option must have argument
heth@mars:~/bin$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.5-15ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.5-15ubuntu1)
heth@mars:~/bin$ uname -a
Linux mars 2.6.35-24-generic #42-Ubuntu SMP Thu Dec 2 02:41:37 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
heth@mars:~/bin$ gcc types.c -o types
heth@mars:~/bin$ ./types
Integer size = 4 - long integer size = 8
================= integer ================
int_max = 2147483647 og int_min = -2147483648
int_max = -2147483648 og int_min = 2147483647
=========== Unsigned integer =============
uint_max = 4294967295
uint_max = 0
==============Long integer ===============
lint_max = 9223372036854775807 og lint_min = -9223372036854775808
lint_max = -9223372036854775808 og lint_min = 9223372036854775807
=========== Unsigned integer =============
ulint_max = 18446744073709551615
ulint_max = 0
heth@mars:~/bin$