C Tutorial/Operator/sizeof operator — различия между версиями


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 14:21, 25 мая 2010

Demonstrating the sizeof operator

#include <stdio.h>
int main()
{ 
   char c;           
   short s;         
   int i;       
   long l;         
   float f;        
   double d;         
   long double ld;   
   int array[ 20 ];  /* create array of 20 int elements */
   int *ptr = array; /* create pointer to array */
   printf( "     sizeof c = %d\tsizeof(char)  = %d"   
           "\n     sizeof s = %d\tsizeof(short) = %d"   
           "\n     sizeof i = %d\tsizeof(int) = %d"   
           "\n     sizeof l = %d\tsizeof(long) = %d"   
           "\n     sizeof f = %d\tsizeof(float) = %d"   
           "\n     sizeof d = %d\tsizeof(double) = %d"   
           "\n    sizeof ld = %d\tsizeof(long double) = %d"   
           "\n sizeof array = %d"   
           "\n   sizeof ptr = %d\n",    
          sizeof c, sizeof( char ), sizeof s, sizeof( short ), sizeof i,
          sizeof( int ), sizeof l, sizeof( long ), sizeof f, 
          sizeof( float ), sizeof d, sizeof( double ), sizeof ld, 
          sizeof( long double ), sizeof array, sizeof ptr );  
   return 0; 
}
sizeof c = 1       sizeof(char)  = 1
     sizeof s = 2       sizeof(short) = 2
     sizeof i = 4       sizeof(int) = 4
     sizeof l = 4       sizeof(long) = 4
     sizeof f = 4       sizeof(float) = 4
     sizeof d = 8       sizeof(double) = 8
    sizeof ld = 12      sizeof(long double) = 12
 sizeof array = 80
   sizeof ptr = 4