CSC373/406: Integers: Types [5/9] Previous pageContentsNext page

Primitive types in C include (with size in bytes, using gcc on x86)

declaration  size   values
char   f;     1      -128 to 127
short  c;     2      -32,768 to 32,767
int    a;     4      -2,147,483,648 to 2,147,483,647
long   b;     4      -2,147,483,648 to 2,147,483,647
float  d;     4      -3.4e38 to 3.4e38   //  7 decimal digits of precision
double e;     8      -1.7e308 to 1.7e308 // 15 decimal digits of precision 

int  h[20];  80      // array of 20 int  (20*4==80)
char i[20];  20      // array of 20 char (20*1==20)

sizeof operator tells you how many bytes something takes up

file:sizeof.c [source]
00001: #include <stdio.h>
00002: 
00003: void fn(int x[ ]) {
00004:   printf("In fn\nint array: %d\n", sizeof x);
00005: }
00006: 
00007: int main() {
00008:   int a;
00009:   long b;
00010:   short c;
00011:   float d;
00012:   double e;
00013:   char f;
00014:   int *g;
00015:   int h[20];
00016:   printf("int: %d\nlong: %d\nshort: %d\nfloat: %d\n", 
00017:          sizeof a, sizeof b, sizeof c, sizeof d);
00018:   printf("double: %d\nchar: %d\nint *: %d\nint array: %d\n", 
00019:          sizeof e, sizeof f, sizeof g, sizeof h);
00020:   fn(h);
00021:   return 0;
00022: }
00023: 

An array parameter is really a pointer!

Previous pageContentsNext page