Reference.Sizeof History

Hide minor edits - Show changes to markup

June 03, 2010, at 07:41 PM by Equipo Traduccion -
Changed lines 3-8 from:

Description

The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array.

Syntax

to:

Descripcion

El operador sizeof devuelve el número de bytes de un tipo de variable, o el número de bytes que ocupan un array.

Sintaxis

Changed lines 11-20 from:

Parameters

variable: any variable type or array (e.g. int, float, byte)

Example code

The sizeof operator is useful for dealing with arrays (such as strings) where it is convenient to be able to change the size of the array without breaking other parts of the program.

This program prints out a text string one character at a time. Try changing the text phrase.

to:

Parametros

variable: cualquier tipo de variable o array (p.e. int, float, byte)

Código de ejemplo

El operador sizeof es útil para tratar con array (tales como strings) donde es conveniente poder cambiar el tamaño del array sin romper otras partes del programa.

Este programa imprime un texto caracter a caracter. Prueba a cambiar el texto de la frase

Changed line 22 from:

char myStr[] = "this is a test";

to:

char miStr[] = "esto es una prueba";

Changed line 30 from:
  for (i = 0; i < sizeof(myStr) - 1; i++){
to:
  for (i = 0; i < sizeof(miStr) - 1; i++){
Changed line 33 from:
    Serial.println(myStr[i], BYTE);
to:
    Serial.println(miStr[i], BYTE);
Changed lines 38-39 from:

Note that sizeof returns the total number of bytes. So for larger variable types such as ints, the for loop would look something like this.

to:

Ten en cuenta que sizeof devuelve el número total de bytes. Por lo que tipos de variables más grandes como enteros (int), el bucle for podría parecerse a algo como esto.

Changed lines 41-42 from:

for (i = 0; i < (sizeof(myInts)/sizeof(int)) - 1; i++) {

  // do something with myInts[i]
to:

for (i = 0; i < (sizeof(miInts)/sizeof(int)) - 1; i++) {

  // haz algo con miInts[i]
May 29, 2007, at 05:32 AM by David A. Mellis - sizeof int doesn't work, it must be sizeof(int)
Changed lines 9-13 from:

sizeof (variable)

sizeof variable

Both forms are accepted by the compiler

to:

sizeof(variable)

April 16, 2007, at 06:54 PM by Paul Badger -
Deleted line 40:
April 16, 2007, at 06:54 PM by Paul Badger -
Deleted lines 49-51:
April 16, 2007, at 08:56 AM by David A. Mellis -
Changed lines 44-47 from:

[@ for (i = 0; i < (sizeof(myStr)/sizeof(int)) - 1; i++) @)

to:
for (i = 0; i < (sizeof(myInts)/sizeof(int)) - 1; i++) {
  // do something with myInts[i]
}

April 16, 2007, at 06:29 AM by Paul Badger -
Changed lines 20-21 from:

This program prints out the text string a character at a time. Try changing the text phrase.

to:

The sizeof operator is useful for dealing with arrays (such as strings) where it is convenient to be able to change the size of the array without breaking other parts of the program.

This program prints out a text string one character at a time. Try changing the text phrase.

April 16, 2007, at 06:26 AM by Paul Badger -
Changed lines 5-6 from:

The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array, to find the

to:

The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array.

Changed lines 9-18 from:

(type)(variable)

Parameters:

type: any variable type (e.g. int, float, byte)

variable: any variable or constant

Example

to:

sizeof (variable)

sizeof variable

Both forms are accepted by the compiler

Parameters

variable: any variable type or array (e.g. int, float, byte)

Example code

This program prints out the text string a character at a time. Try changing the text phrase.

Added line 23:

char myStr[] = "this is a test";

Changed lines 25-28 from:

float f;

f = 3.6; i = (int) f; // now i is 3

to:

void setup(){

  Serial.begin(9600);

}

void loop() {

  for (i = 0; i < sizeof(myStr) - 1; i++){
    Serial.print(i, DEC);
    Serial.print(" = ");
    Serial.println(myStr[i], BYTE);
  }

}

Changed lines 40-43 from:

Note

When casting from a float to an int, the value is truncated not rounded. So both (int) 3.2 and (int) 3.7 are 3.

to:

Note that sizeof returns the total number of bytes. So for larger variable types such as ints, the for loop would look something like this.

[@ for (i = 0; i < (sizeof(myStr)/sizeof(int)) - 1; i++) @)

April 16, 2007, at 05:37 AM by Paul Badger -
Added lines 1-31:

sizeof

Description

The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array, to find the

Syntax

(type)(variable)

Parameters:

type: any variable type (e.g. int, float, byte)

variable: any variable or constant

Example

int i;
float f;

f = 3.6; 
i = (int) f; // now i is 3

Note

When casting from a float to an int, the value is truncated not rounded. So both (int) 3.2 and (int) 3.7 are 3.

Reference Home

Share