IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
C++
Search C++ Group:

Advanced
-Collapse +Expand C++ To/From
To/FromCODEGuides
-Collapse +Expand C++ Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C++ Store
PRESTWOODSTORE

Prestwood eMagazine

April Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingC++C++/CLIC++/CLI Lang...   Print This     
  From the January 2016 Issue of Prestwood eMag
 
C++/CLI Language Basics:
C++/CLI Constants (const or literal)
 
Posted 16 years ago on 1/13/2009
C++ Code Snippet:
 A flashcard from our C++ Flashcards Library
 A code snippet from our C++ Code Snippets Page
 Tags: C++/CLI , Constants

KB101805

General Info: Computer Language Constants

A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.

C++/CLI Constants

C++/CLI supports the const and static const keywords of standard C++ as well as the new literal keyword. A literal is equivalent to static const in standard C++ and Microsoft's documentation recommends to replace static const with the new literal keyword because a literal is available in metadata; a static const variable is not available in metadata to other compilers.

You can use static const within the class declaration or locally within a method. However, literal is only valid in the class declaration section and const is only valid within a method.

Syntax Example:
//some method {
const String^ MyName = "John";
static const Int32 MyAge = 27;
//}
// public class SomeClass : public Object {
public:
  literal double Pi = 3.14159;
  literal String^ MyName = "Mike";
  static const Int32 MyAge = 35;
//...

More Info

Definition:  Computer Language Constants

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1234A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: True or False?

Constants defined as static const are not viewed as a constant by the CLR runtime.

Syntax Example:

static const int PI = 3.14;
Answer:
  • True
  • False

  •  KB Article #101805 Counter
    21544
    Since 1/13/2009
    Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
    www.prestwood.com


    ©1995-2025 Prestwood IT Solutions.   [Security & Privacy]