Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created July 18, 2012 08:36
Show Gist options
  • Save hpcx82/3135069 to your computer and use it in GitHub Desktop.
Save hpcx82/3135069 to your computer and use it in GitHub Desktop.
You can only initialize array on declaration for stack variables
#include <iostream>
using namespace std;
int main()
{
// initialize stack array variable
int x[] = {1, 3, 4};
int b[][2] = {{1, 2}, {3, 4}};
// heap array variable can't assign initial value
int* a = new int[5]{1, 3, 5, 7, 9}; // compiler error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment