Demonstrating the sizeof operator : sizeof operator « Operator « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » Operator » sizeof operator 
5.10.1.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 array20 ];  /* 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, sizeofchar ), sizeof s, sizeofshort ), sizeof i,
          sizeofint ), sizeof l, sizeoflong ), sizeof f, 
          sizeoffloat ), sizeof d, sizeofdouble ), sizeof ld, 
          sizeoflong 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
5.10.sizeof operator
5.10.1.Demonstrating the sizeof operator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.