Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:45:08+00:00 2026-06-14T04:45:08+00:00

Is there a difference between the following definitions? const double PI = 3.141592653589793; constexpr

  • 0

Is there a difference between the following definitions?

const     double PI = 3.141592653589793;
constexpr double PI = 3.141592653589793;

If not, which style is preferred in C++11?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:45:09+00:00Added an answer on June 14, 2026 at 4:45 am

    I believe there is a difference. Let’s rename them so that we can talk about them more easily:

    const     double PI1 = 3.141592653589793;
    constexpr double PI2 = 3.141592653589793;
    

    Both PI1 and PI2 are constant, meaning you can not modify them. However only PI2 is a compile-time constant. It shall be initialized at compile time. PI1 may be initialized at compile time or run time. Furthermore, only PI2 can be used in a context that requires a compile-time constant. For example:

    constexpr double PI3 = PI1;  // error
    

    but:

    constexpr double PI3 = PI2;  // ok
    

    and:

    static_assert(PI1 == 3.141592653589793, "");  // error
    

    but:

    static_assert(PI2 == 3.141592653589793, "");  // ok
    

    As to which you should use? Use whichever meets your needs. Do you want to ensure that you have a compile time constant that can be used in contexts where a compile-time constant is required? Do you want to be able to initialize it with a computation done at run time? Etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any difference between the following two examples and should one be preferred
Is there any difference between following two ways of creating an object. Student s1
Is there a difference between the following two : ArrayList list = getData(); public
Is there a difference between the following two statements: mysql> EXPLAIN SELECT IF(arms IS
Is there a difference between the following selectors: var index = $(this).parent().index(); var index2
Question 1 Can anyone tell me if there is any difference between following 2
Is there a performance difference between the following 2 queries, and if so, then
Is there a functional difference between the following syntax... [Foo, Bar] public class Baz
Will there be a difference between the following two ways of calling a function
I'd like to know if there's a difference between the following two calls to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.