Created
July 18, 2012 08:36
-
-
Save hpcx82/3135069 to your computer and use it in GitHub Desktop.
You can only initialize array on declaration for stack variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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