Pikir dan Rasa

cogito ergo sum

Ukuran dari variabel (datatypes) pada Arduino

leave a comment »

Berikut adalah kode hasil modifikasi dari kode pada sizes.c [ref], yang disesuaikan khusus untuk sistem Arduino. Untuk mendapatkan hasilnya kita perlu mengaktifkan “Serial Monitor”.

/*

 Modifikasi dari sizes.c

*/

void setup() {

  Serial.begin(9600);
   
  Serial.print("Bytes per char          : "); Serial.println((sizeof(char)));
  Serial.print("Bytes per unsigned char : "); Serial.println((sizeof(unsigned char)));
  Serial.print("Bytes per short         : "); Serial.println(sizeof(short));
  Serial.print("Bytes per unsigned short: "); Serial.println(sizeof(unsigned short));
  Serial.print("Bytes per int           : "); Serial.println(sizeof(int));
  Serial.print("Bytes per unsigned int  : "); Serial.println(sizeof(unsigned int));
  Serial.print("Bytes per long          : "); Serial.println(sizeof(long));
  Serial.print("Bytes per unsigned long : "); Serial.println(sizeof(unsigned long));
  Serial.print("Bytes per float         : "); Serial.println(sizeof(float));
  Serial.print("Bytes per double        : "); Serial.println(sizeof(double));
  Serial.print("Bytes per long double   : "); Serial.println(sizeof(long double));
  Serial.print("Bytes per size_t        : "); Serial.println(sizeof(size_t));
}

void loop() {
 
}

 

Hasil:


 

Ref:

http://www.cs.princeton.edu/courses/archive/spr06/cos217/precepthandouts/04/sizes.c

 


Written by sunupradana

February 16, 2012 at 2:52 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: