When declare array, what value hold on their memory address [duplicate] - c++

This question already has answers here:
What happens when I print an uninitialized variable in C++? [duplicate]
(4 answers)
Uninitialized variable behaviour in C++
(4 answers)
Is uninitialized local variable the fastest random number generator?
(22 answers)
Why do I see strange values when I print uninitialized variables?
(6 answers)
Closed 3 years ago.
If not declare value in an array, then what value hold on the memory address.
Where did these outputs come from?
int main()
{
int a[10];
cout<<a[2]<<endl;
cout<<a[2]<<endl;
cout<<a[3]<<endl;
cout<<a[3]<<endl;
return 0;
}
//Given Output
//1978190368
//1978190368
//1129149863
//1129149863

Related

no matching function for call to ‘make_shared<unsigned char [x]>()’ [duplicate]

This question already has answers here:
Can you allocate an array with something equivalent to make_shared?
(4 answers)
shared_ptr to an array : should it be used?
(2 answers)
Closed 8 days ago.
I am using a template called Temp, and I have a shared pointer defined like this
std::shared_ptr<Temp[]> ptr;
I use make shared like this
this->ptr = std::make_shared<Temp[x]>();
Where x is int value for the number of elements I want to store.
int x = this->GetSize();
I get this error:
error: no matching function for call to
‘make_shared<unsigned char [x]>()’

How to get variable length array [duplicate]

This question already has answers here:
C++ : Creating an array with a size entered by the user
(3 answers)
How to create a dynamic array of integers
(8 answers)
Closed 1 year ago.
I know variable length arrays are not allowed in c++. My code is currently as follows:
int main(){
int t;
cin >> t;
double h[t];
}
How can I create an array with length t then?
Edit: the assignment only allows char, bool, int and double. Vector isn't allowed. When I tried to compile it, it says ISO C++ forbids variable length array 'h'.

Vector of vectors to array of arrays [duplicate]

This question already has answers here:
How to convert vector to array
(10 answers)
C++ vector<vector<double> > to double **
(3 answers)
Closed 4 years ago.
I have a variable std::vector<std::vector<float>> I want to pass this variable to a function which accepts array of array of float **float. I was wondering if there is any way to do this?

Why output of 'p' and '&p' is not same for 'int* p' in c++;? [duplicate]

This question already has answers here:
Address of pointer
(5 answers)
C: Why do pointer and &pointer have different values?
(4 answers)
Closed 5 years ago.
Here p is int type of pointer variable.In my code as per I understand output will be same for two line.But it doesn't.So I want to konw why it doesn.t?
#include<iostream>
using namespace std;
int main(){
int* p;
cout<<p<<endl; //0x41c2de
cout<<&p<<endl; //0x28ff0c
}
Question: Why output of two line is not same??

Weird behavior while printing character array in file in C [duplicate]

This question already has answers here:
Returning a reference to a local or temporary variable [duplicate]
(5 answers)
Can a local variable's memory be accessed outside its scope?
(20 answers)
Return address of local variable in C
(5 answers)
Closed 9 years ago.
I saw some weird behavior with my C++ function whose work is to simply put 'n' ones(1).
char *getSpaces(int n) {
char s[50];
int i = 0;
for(i=0; i<n; i++) {
s[i] = '1';
}
s[i] = 0;
return s;
}
When I do fout<< getSpaces(20), I get following output in the file :-
1111111111SOME_WEIRD_CHARACTERS_HERE
Can anybody explain this?
P.S. I am using codeblocks IDE on windows platform.