What does int flag = 1 or flag = 0 means in C++ language? I have seen it in many programs but I don't know its use.
It just means you are declaring a variable called flag and giving it a value of 1 or 0. This will presumably be used elsewhere in the code to keep a track of the state of something. It is also probably boolean in nature.
The elaborate on DaveAmour's answer, you should know that C (the predecessor of C++) does not have a built-in boolean datatype, and until the C99 standard didn't have a standard defined one either. Thus, it has long been the convention in C to use
int variables as booleans, with 0 for false and any other value for true.
While C++ has always had a
bool type, a lot of C++ programmers who had started out in C never got into the habit of using it, and a lot of C programs which were converted to C++ were never changed to use it, either.
The variable name
flag (or some variation thereof) generally indicates that the variable is being used as a boolean value, and more specifically, a flag value, that is, one used to indicate a particular state or state change in the program. In file formats, an
int value may actually hold several packed flag fields, with the individual bits being treated as separate boolean values. However, in the context you are describing, it is more typical for it to hold just a single boolean value.
Edited 1 Year Ago by Schol-R-LEA
I am developing a simple job card creator application with VB.net 2012, using Access 2010 as database.
The code I have generated to write data from a datagridview to the database table is successfully saving the data, but with an error "Parameter @name has no default value". The ...
write a C++ program which take inputs from the user/keyboard and calculate his ZAKAT.
get the input from user may include
-Amount invested in business
-Amount given to other business partners as loan
-Amount payable to others
I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding ...