reellearning

Using the sizeof operator in C++

Jun 27th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. /*
  2.  * sizeof.cpp
  3.  *
  4.  *  Created on: Jun 27, 2012
  5.  *      Author: Derek
  6.  *
  7.  *  Some examples of using the sizeof operator
  8.  */
  9.  
  10. #include <iostream>
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     cout << "int: " << sizeof(int) << " bytes" << endl;
  16.     cout << "boolean: " << sizeof(bool) << " bytes" << endl;
  17.  
  18.     int a[5];
  19.  
  20.     cout << "The size of a five element int array is " << sizeof(a) << " bytes." << endl;
  21.     cout << "The number of elements in the array 'a' is " << sizeof(a) / sizeof(int) << "." << endl;
  22.  
  23.     cout << "The size of an int pointer is " << sizeof(int*) << " bytes." << endl;
  24.     cout << "The size of an double pointer is " << sizeof(double*) << " bytes." << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment