I have got a problem from my friends. The problem is Without initialization of variable how to print 0 to 10?
I know method to print using for loop using initialization
for(int i=0;i<=10;i++) {
cout<<i;
}
Here int i = 0
was initialized. Then how can one print 0 to 10 values without initialization of the relevant variable? It is possible or not?
In C and C++, local variables aren't initialized by default. Uninitialized variables can contain any value, and their use leads to undefined behavior. Warning C4700 almost always indicates a bug that can cause unpredictable results or crashes in your program.
In the low-level efficiency tradition of C and C++ alike, the compiler is often not required to initialize variables unless you do it explicitly (e.g., local variables, forgotten members omitted from constructor initializer lists).
If you declare a final variable later on you cannot modify or, assign values to it. Moreover, like instance variables, final variables will not be initialized with default values. Therefore, it is mandatory to initialize final variables once you declare them.
An uninitialized variable is a variable that has not been given a value by the program (generally through initialization or assignment). Using the value stored in an uninitialized variable will result in undefined behavior.
Your friends should learn to specify their problems more precisely.
int i; // i is not initialized
i = 0; // i is assigned
for( ;i<=10;i++)
{
cout<<i;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With