1int nums[100] = {0}; // initiallize all values to 0
2
3int nums[5] = {1,2,3,4,5};
4
5// type name[size] = {values};
1int* a = NULL; // Pointer to int, initialize to nothing.
2int n; // Size needed for array
3cin >> n; // Read in the size
4a = new int[n]; // Allocate n ints and save ptr in a.
5for (int i=0; i<n; i++) {
6 a[i] = 0; // Initialize all elements to zero.
7}
8. . . // Use a as a normal array
9delete [] a; // When done, free memory pointed to by a.
10a = NULL; // Clear a to prevent using invalid memory reference.
11
1#include <iostream>
2using std::cout;
3
4int a[] = { 1, 2, 3, 4, 5 };
5int counta()
6 {
7 return sizeof( a ) / sizeof( a[ 0 ] ); // works, since a[] is an array
8 }
9
10int countb( int b[] )
11 {
12 return sizeof( b ) / sizeof( b[ 0 ] ); // fails, since b[] is a pointer
13 }