answersLogoWhite

0

The main two I can think of:

  1. It gives more meaning to the constant. eg using PI instead of 3.14159 makes it easier to understand what's going on when calculating things like a = PI * r * r;
  2. Should the constant for the program need to be changed, only one occurrence needs to be changed (in a header file) instead of all usages.
User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What are constants in computer programming?

A constant may refer to a literal constant, a constant variable. A literal constant is a value that we use to initialise or assign to a variable, literally, such as: int x {42}; // initialise x = 0; // assign Here, the values 42 and 0 are literal constants. A constant variable is a variable which will not change value after initialisation: const int x {42}; // initialise x = 69; // error - cannot assign to a constant variable Constant variables are useful when we wish to use the same constant value repeatedly within a scope. We could also use a literal constant rather than a constant variable, however naming our constants makes it easier to refer to the value consistently, particularly during code maintenance where we may wish to review the value. With a constant variable we need only change the initialiser, but with literal constants we must change every occurrence of the literal and that can lead to inconsistencies. Consider the following: int x[100]; int y[100]; for (int i=0; i<100; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<100; ++i) { cout << y[i] << endl; } Here we've used the literal constant 100 four times. At a future time we may decide array x really needs 200 elements rather than 100, but we have to be careful which literals we change because array y makes use of that same literal constant. Using constant variables helps keep those usages separate: const int xmax {100}; const int ymax {100}; int x[xmax]; int y[ymax]; for (int i=0; i<xmax; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<ymax; ++i) { cout << y[i] << endl; } Now we can safely change the xmax initialiser without affecting any usage of the ymax constant: const int xmax {200}; const int ymax {100}; int x[xmax]; int y[ymax]; for (int i=0; i<xmax; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<ymax; ++i) { cout << y[i] << endl; } Note that a constant variable cannot be initialised by a non-constant variable: int x {42}; const int y {x}; // error - x is non-constant


Can you declare constructor as constant if yes why?

Constructors are implicitly constant members of a class. They do not modify objects, rather they initialize them. So constant and not constant objects can invoke them: const MyClass object; // invokes MyClass::MyClass() constructor


What are advantages of telecomunication in an organization?

It save people a lot of time rather then walking


What are symbolic constants and how they are useful in developing programs?

symbolic constants are named constants like : final double PI = 3.14 ; They are constants because of the 'final' keywords, so they canNOT be reassigned a new value after being declared as final And they are symbolic , because they have a name A NON symbolic constant is like the value of '2' in expression int foo = 2 * 3 Answer given By Sushil Mittal..........


What advantages does 2 by 6 studs have over 2 by 4 studs?

You can get more insulation when using 2x6 studs rather than 2x4 studs

Related Questions

What is the meaning of constant variables?

Constant variables are variables that, once initialized, do not change in value. They are effectively the same as literal constants, except that you can use symbolic names to make it easier to understand the meaning of the program. For instance, in a trigonometry program, it is easier to use the identifier PI than it is to use the literal 3.1415926535897932. Also, if you have a constant that might be adjustable, such as a factor in an equation, naming it allows you to change its value by changing only one line of code, rather than seeking out all of the lines of code that refer to the factor. Constant variables are also candidates for being placed in read-only memory, potentially making the program more secure.


What does figuratively speaking mean?

Figuratively speaking refers to using language in a symbolic or metaphorical way, rather than in a literal sense. It is a way of expressing ideas or concepts indirectly for emphasis or imaginative effect.


What advantage are there in defining an array size in term of symbolic constant rather than a fixed integer value?

It may be possible to generalise results to other integer values.


Are symbolic creatures mortal enemies?

Symbolic creatures often represent opposing forces or ideals, making them seem like mortal enemies in various narratives. However, their conflict is more about the underlying themes they embody, such as good versus evil or chaos versus order, rather than a literal enmity. In many stories, these creatures can coexist or even find common ground, reflecting the complexity of their symbolic roles. Ultimately, their relationship serves to highlight deeper moral or philosophical questions rather than simply portraying them as adversaries.


What is Augustine's interpretation of the literal meaning of Genesis?

Augustine's interpretation of the literal meaning of Genesis is that it should not be taken strictly as a historical or scientific account, but rather as a symbolic and allegorical representation of spiritual truths. He believed that the creation story in Genesis should be understood in a way that aligns with Christian teachings and the pursuit of a deeper understanding of God's plan for humanity.


Did leviathan really exist?

The Leviathan is a mythological sea creature mentioned in various religious texts and folklore. There is no scientific evidence to suggest that a real-life Leviathan exists. It is believed to be a symbolic representation of chaos or a powerful force rather than a literal creature.


Where do Protestants get that transubstantion is wrong?

Generally speaking, Protestants believe that the wine and bread in communion take on a special meaning but not in a literal sense. They do not believe the wine is the actual literal blood of Jesus and they do not believe the bread is the actual literal body of Christ. They believe He symbolically offered Himself as the Paschal Lamb of atonement. In my opinion, this is something we can debate vigorously but do not have to divide over.


Why is it important to keep all variables but one constant in a scientific experiment?

Because changing more than one variable will change the entire experiment. Changing one variable allows you to see how things could have turned out under different circumstances.If you keep all the variables different, you won't be able to determine what variable lead to which outcome. So just make sure you keep ONE variable different (the one you are testing) because this is crucial to your whole experiment.


The advantages of the literal rule?

follows parliament supremacy and makes sure all judges do is APPLY the law rather than make itintended to demand precision with drafting so that anyone that can read English can understand the law


What are constants in computer programming?

A constant may refer to a literal constant, a constant variable. A literal constant is a value that we use to initialise or assign to a variable, literally, such as: int x {42}; // initialise x = 0; // assign Here, the values 42 and 0 are literal constants. A constant variable is a variable which will not change value after initialisation: const int x {42}; // initialise x = 69; // error - cannot assign to a constant variable Constant variables are useful when we wish to use the same constant value repeatedly within a scope. We could also use a literal constant rather than a constant variable, however naming our constants makes it easier to refer to the value consistently, particularly during code maintenance where we may wish to review the value. With a constant variable we need only change the initialiser, but with literal constants we must change every occurrence of the literal and that can lead to inconsistencies. Consider the following: int x[100]; int y[100]; for (int i=0; i<100; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<100; ++i) { cout << y[i] << endl; } Here we've used the literal constant 100 four times. At a future time we may decide array x really needs 200 elements rather than 100, but we have to be careful which literals we change because array y makes use of that same literal constant. Using constant variables helps keep those usages separate: const int xmax {100}; const int ymax {100}; int x[xmax]; int y[ymax]; for (int i=0; i<xmax; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<ymax; ++i) { cout << y[i] << endl; } Now we can safely change the xmax initialiser without affecting any usage of the ymax constant: const int xmax {200}; const int ymax {100}; int x[xmax]; int y[ymax]; for (int i=0; i<xmax; ++i) { cout << x[i] << endl; } // ... for (int i=0; i<ymax; ++i) { cout << y[i] << endl; } Note that a constant variable cannot be initialised by a non-constant variable: int x {42}; const int y {x}; // error - x is non-constant


Does the pillar of salt exist today?

The pillar of salt mentioned in the Bible, specifically in the story of Lot's wife turning into a pillar of salt, is a religious and mythological concept. There is no scientific evidence or archaeological findings to support the existence of a literal pillar of salt today. It is considered a symbolic or metaphorical element within the biblical narrative, rather than a physical object that still exists.


What is an expression of a meaning that contradicts the literal meaning?

An expression of a meaning that contradicts the literal meaning is called an idiom. Idioms are phrases that have a figurative rather than literal meaning, often making them difficult to understand when translated directly.