(Assuming includes/namespace std/prototypes in the lines above code)
1) Is it safe to create a reference to a declared variable that isn't initialized?
myVariable
is declared in line 2 and then myRef
is set to reference the uninitialized myVariable
in line 3.
Is this something that shouldn't be done?
1- int main(){
2- string myVariable;
3- string& myRef = myVariable;
4- {
2) Is it safe to initialize an uninitialized variable by passing itself through as a reference to a function?
myVar
is declared on line 2 and then initialized on line 3 but it uses its uninitialized self as an arguement in the function askText
. Inside the function on line 3('7'), the reference text_to_initialize
gives myVar
a value finally.
Is it safe to intialize with yourself as an arguement in line 3?
1- int main(){
2- string myVar;
3- myVar = inputText(myVar);
4- }
5-
6- string inputText(string& text_to_initialize){
7- cin >> text_to_initialize;
8- return (text_to_initialize + "!");
8- }