Arrays in C++.
How to create an array in C++.
Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 05:42 PM
#include <iostream>
int main() {
int nMyArray[] = { 1, 2, 3, 4, 5 };
int nMyArray2[6] = { 1, 2, 3, 4, 5, 6 }; // you can specify the length if you want
std::cout << sizeof(nMyArray) << " is the number of bytes in array" << std::endl;
// integers are 4 bytes, or 32 bits so divide by four
std::cout << sizeof(nMyArray)/4 << " is the size of array" << std::endl;
for (int i = 0; i < 5; i++) {
std::cout << nMyArray[i] << std::endl;
}
std::cout << sizeof(int) << " is the number of bytes in a integer" << std::endl;
std::cout << sizeof(float) << " is the number of bytes in a float" << std::endl;
std::cout << sizeof(double) << " is the number of bytes in a double" << std::endl;
std::cout << sizeof(char) << " is the number of bytes in a char" << std::endl;
std::cout << sizeof(bool) << " is the number of bytes in a boolean" << std::endl;
return 0;
}
Downloads:
Download: arrays.cpp 928 B
Please login or Click Here to register for downloads
Arrays by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
