Skip to content

error: variable-sized object may not be initialized #394

@jetcoder

Description

@jetcoder

Full error message:

/home/insights/insights.cpp:8:10: error: variable-sized object may not be initialized
        int arr[num] {};
                ^~~
1 error generated.
Error while processing /home/insights/insights.cpp.

During following code running:

#include <iostream>

int main()
{
	int num;
	std::cin >> num;	
	
	int arr[num] {};
	
	for (auto& item : arr)
	{
		std::cout << item << " ";
	}
	std::cout << std::endl;
		
}

The error is shown for C++ standards from 11 to 20a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions