How to reset a vector which is was declared globaly [duplicate] - c++

This question already has answers here:
class std::vector has no member named [closed]
(3 answers)
How to print vector's data
(3 answers)
No operator "=" matches these operands
(2 answers)
Closed 5 years ago.
when using the fill method or clear the following error appears
request for member ‘clear’ in ‘adj’, which is of non-class type ‘std::vector [1000005]
the declaration is as follows:
vector<int> adj[1000005];

It's not a vector but an array of 1000005 vectors. To properly define a global vector you'll need to use parentheses (or braces):
vector<int> adj(1000005);

Related

What does int arr[10]{} this declaration in C++ means? [duplicate]

This question already has answers here:
Use of Curly Brackets (Braces) Around a variable C++
(4 answers)
Initialization difference with or without curly braces in C++
(3 answers)
What are the advantages of list initialization (using curly braces)?
(5 answers)
When should we use parenthesis ( ) vs. initializer { } syntax to initialize objects in C++11? [duplicate]
(2 answers)
When to use the brace-enclosed initializer?
(3 answers)
Closed 3 months ago.
int fr[10]{}
I seen this declaration in C++ is this 1-D array or it is 2-D. Which type of declaration it is?
C++ since its version 11 has introduced in its standard the use of curly brackets for the initialization of objects.
Here are some examples:
MyObjects obj {};
MyObjects obj {firstParameter};
int array[10] {};
In the latter case, it refers to the fact that it will contain 10 elements initialized as zero in it. In the case of the standard types you will see what was written in the memory cell first
Here you will find a precise explanation of all this

what is the difference between these two way to assign array in C++? [duplicate]

This question already has answers here:
difference between two array declaration methods c++
(4 answers)
What is the difference between Static and Dynamic arrays in C++?
(13 answers)
Closed 10 months ago.
int numList1[10];
int *numList2 = new int[10];
I have seen too many solutions from others used the second way to assign array, do they work as the same?

Declaring array ( Variables behind each other) in heap without initial values [duplicate]

This question already has answers here:
c++ initial value of dynamic array
(6 answers)
How can I make `new[]` default-initialize the array of primitive types?
(4 answers)
Initialization of array on heap
(7 answers)
C++: new call that behaves like calloc?
(11 answers)
Operator new initializes memory to zero
(4 answers)
Closed 3 years ago.
What it the initial values of an array declared in the heap. it's a zero or random values in memory?
int* ptrAr;
ptrAr = new int[5];

different types of array declaration in c++ [duplicate]

This question already has answers here:
What and where are the stack and heap?
(31 answers)
Array as array[n] and as pointer array*
(2 answers)
Closed 5 years ago.
I have just been starting with C++ and I have come across multiple types of array declaration in C++
int data[3];
and other type is,
int *data= new data[3];
What is the difference between the two?
Since, I have not allocated memory in the first case will I overwrite memory which may already be in use and potentially cause segmentation error?

are there any benefits to use initialization instead of assignment in C++? [duplicate]

This question already has answers here:
Is there a difference between copy initialization and direct initialization?
(9 answers)
Direct Initialization vs Copy Initialization for Primitives
(4 answers)
Closed 9 years ago.
I read the following code in c++:
bool result(false);
is result initialized as false?
but are there any benefits to do it instead of:
bool result = false;
can anyone help?