what is the benefit to use it in the program.Is the flag work as same as variables?If yes,then we can use variable in the place of flag?Please clear it.Why are we used flag in the programming?Is any subsitute of it?if yes then what?Actual use of Flag?
Please explain this concept with appropriate example?
Thanks in advance
What is the basic concept behind using the flag in the programming of C/C++?
if i'm not wrong, i think u misunderstood what flag means. 'Flag' is not a 'special terms' (like variable, argument, loop and parameter) in programming language but it IS a term that is widely used in coding.
The term 'Flag' is commonly use as a mark or reference to certain state or criteria. Flag can be in variable or can be returned by a function, depends on the code and the purpose of the code itself. U cannot use flag instead of variable because Flag is usually a variable.
For example, a programmer is creating a program that will print out a line in the screen and optionally if the printer is on, it will print it out on paper. He will first write code to check whether his printer is on or off. He will use the variable bPrinter to store the result. True if the printer is on or False if the printer is off. He will then write codes to print a line to the screen and some more codes to ask the user whether to print it out or not. If the user insist on printing it, he will refer to bPrinter variable to check the state of the printer. If it is on (bPrinter = True) then the line will be printed out. If not (bPrinter = False) then no print out.
Here the variable bPrinter is used as a 'Flag' to mark the state of the printer. I hope u understand this example.
Good Luck
Reply:flags are variables
Reply:A flag is a variable that is used to indicate one of many limited states.
In most cases a flag is a true/false or on/off variable. Much the same way as you would either raise a red/green flag. In such cases a boolean variable is used. An example would be the exit condition of a while loop.
In other cases a flag might be 3/4/5... ways. In these cases an int or an enum variable is used with different states being defined to indicate different states. For example, when comparing 2 strings, string1 can be less than string2, more than string2 or equal to string2. A string comparison function will return an integer flag with -1, +1 or 0 values respectively in each of these cases.
Hope this helps.
potential break up song
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment