It is the direct initialisation of RN with 0.Quote:
Originally Posted by jackson6612
Printable View
It is the direct initialisation of RN with 0.Quote:
Originally Posted by jackson6612
Thanks a lot, Jim. I'm having little difficulty in interpreting the bold part. Are you saying that when I enclose both the if statement and the if block within the braces, then when I get out of the the braces, any data created will be go away? As you see I'm confused, please help me.
Okay. I understand it now that the proper way to use the braces for the block of if statement is not to include the if statement within the braces itself.
You used the word "control statement". I was understand the impression that the if statement is decision statement and the statements such as "while (. . .)" are condition statements. Is the word "control statement" used to refer to both decision and condition statements. Please advise me.
I'm very much grateful for all the help and guidance.
Hi laserlight :)
I understand it now. But this format seems confusing and misleading to a novice like me. The things like "RN( )" are called function calls and when put some value within the parentheses it's called argument of the function call. But as we know RN() is not a function call in the present context, at least. So, what do you say on this? Please let me know. Thanks.
Hi
I think two posts from this thread are gone because of recent problem with the forums.
I'm still struggling to understand what will really happen if I enclose both the if statement and the if block within the braces such as:
I understand one can define local variables within the block without making them visible outside the block. Please guide me.Code:{
if (...)
//statements
}
Quote:
I'm still struggling to understand what will really happen if I enclose both the if statement and the if block within the braces such as:
The primary problem with this brace placement is that if you add another statement after the if that statement would not be part of the if statement. To illustrate the problems that improper brace placement can cause enter the following program and compile.Code:{
if (...)
//statements
}
Note: This code should not compile. Do you understand why?Code:#include <iostream>
using namespace std;
int main()
{
int varToShowInit(1000);
cout << "varToShowInit before block " << varToShowInit << endl;
{
if(false)
cout << "Part of the if statement. Shoule not print " << endl;
cout << "NOT part of the if statement." << endl;
cout << "varToShowInit in block " << varToShowInit << endl;
int varToShowError = 100;
cout << "varToShowError in block " << varToShowError << std::endl; // Ok, variable still in scope.
int varToShowInit = 20;
cout << "varToShowInit in block " << varToShowInit << endl;
}
cout << "varToShowInit after block " << varToShowInit << endl;
cout << varToShowError << endl; // Error this variable is not defined.
return 0;
}
Now comment out the line that is causing the error.
Now this code should compile and run, do you see any possible problems with varToShowInit printed values?
Jim