answersLogoWhite

0

How do you declare a constant?

Updated: 9/18/2023
User Avatar

Wiki User

13y ago

Best Answer

use:

define("GREETING", "Hello you.", true);

1st parameter is the name for your constant

2nd parameter is the value of that constant

3rd parameter is whether or not you want the constant to be case-insensitive. Default is case sensitive.

http://php.net/manual/en/function.define.php

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare a constant?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you use define in C?

Just type declare then the variable that you desire to assigned a certain constant value on it. Just type declare then the variable that you desire to assigned a certain constant value on it.


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 is a symbol representing value that doesn't change?

It is often represented by c for constant or k for its phonetic equivalent. But as long as you declare it as a constant, any symbol will do.


How would you declare a constant of 5 called MYCONST?

A constant of 5 called MYCONST would be declared as #define MYCONST 5. This is because the statement used is a define statement.


How do you declare a string and character constant?

public static final String WELCOME_MESSAGE = "Hello, welcome to the server";


How do you declare and initialize constant arrays?

example in C: const int a [] = {10, 20, 40, 80};


How do you declare constant in Turbo C?

In C there is no constant with a name. It is done with the preprocessor directive of #define as in #define pi 3.1416 The preprocesor substitutes every occurance of word pi (with blanks on either side) with 3.1416


How do you declare a constant Explain it with a suitable example?

Declaring a Constant: We can declare a constant using the keyword "const". E.g. const abc='a';const number=10; const number[10]={1,2,3,4,5,6,7,8,9,10}; const name[7]={'K','U','N','D','A','N'}; #include<stdio.h> #include<conio.h> void main() { int i; const name[7]={'K','U','N','D','A','N'}; for(i=0;i<7;i++) { printf("%c",name[i]); getch(); }


What are the examples of string constant?

In Java, a string constant is a text within double quotation marks. Example:String playerName = "Player 1"; // Assign a default name initiallyHere, the string constant was assigned to variable playerName. If you don't want the value to change later, declare it as final:final String greeting = "Hello!"


Which access specifier is preferred for constant variables?

There's no such thing as a constant variable (other than as an oxymoron). A named value is either declared constant or it is declared variable, it cannot be both a constant and a variable.You declare a constant much as you would a variable, except you use the final keyword modifier and name the constant using ALL CAPS and underscores for spaces.final int HOURS_IN_DAY = 24;final int DAYS_IN_WEEK;DAYS_IN_WEEK = 7;Note that we don't need to assign a constant value at the point of instantiation. However, once assigned we cannot then change the value. It wouldn't be a constant if we could!The preferred access specifier depends on how useful the constant is. If only one method makes use of the constant, then it should simply be declared within that method as a local constant. If several methods of the same class make use of the constant then declare it a private member of the class. Both methods are used in the following example:public class MyClass {private static int HOURS_IN_DAY = 24;public int hoursInDays (int days) {return days * HOURS_IN_DAY;}public int hoursInWeeks (int weeks) {final int DAYS_IN_WEEK = 7;return weeks * DAYS_IN_WEEK * HOURS_IN_DAY;}}Note the use of the static keyword in the constant declaration. It doesn't make sense for every object of a class to store independent copies of the same constant value, thus we must declare class constants as static members so that all objects of the class can share the same instance of the constant and thus share the same value.If we want the constant to be accessible to our subclasses, then we can declare the constant protected. If we want to make the constant available outside of the class then we can declare it public.Keep in mind that although constants are not variable, we should only expose what needs to be exposed outside of a class, no more and no less. A constant that provides a class implementation detail has no business being accessible outside of the class in which it is declared.You should also be aware that the rules governing constants are different for primitive data types and objects. With primitive data types, the value is constant as one would expect. But with objects, only the reference is constant (we cannot refer to a different object) but if the referenced object allows mutations then it is not truly constant. Unfortunately, the only way to create a truly constant object from a mutable class is to subclass the mutable class and render its setters private.


Differentiate c constant and c variables?

Differentiate between constants and variableConstantsvariablescharacteristicsValue is not changeableduring the course of the programValue can be changedanytime during the course of the programusageUse constant when you want to declare something that won't change midway in your program execution.Use variable to store data thatmay or will change during the running of the program.


To declare positively?

to declare positively