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

  • SEARCH
  • Home
  • 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 975463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:35:19+00:00 2026-05-16T03:35:19+00:00

It is always better for contants such as PI to #define them or declare

  • 0

It is always better for contants such as PI to #define them or declare them const so the compiler can optimize and it becomes less error prone. I was wondering however, how are literal numbers in statements treated? Ex:

float x;
const int y = 60;
x = y / 3.0f;

In this example how would 3.0f be treated? Would it inherit the optimizations of a constant?

  • 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-05-16T03:35:19+00:00Added an answer on May 16, 2026 at 3:35 am

    What optimizations will take place depends on the compiler. In your case, both C and C++ compilers will normally have enough information to optimize your source code into identical machine code. In other words, it doesn’t really depend much on what is literal and what is constant in this code.

    Having said that, the meaning of the terms literal and constant are significantly different in C and C++ (and you tagged your question C and C++ at the same time).

    • In C 60 and 3.0f are constants, but y is not a constant. You can call y a const-qualified variable if you wish, but it is not a constant in C terminology, in a sense that a single y is not a constant expression in C.

    As for literals, in C language the term literal only applies to string literals (and also compound literals in C99), i.e. there are no literals in your code at all.

    • In C++,60 and 3.0.f are literals, which form constant expressions (integral and floating -point respectively). y is also a constant of int type, in a sense that a single y is a constant expression in C++.

    The situation when you might notice the difference has nothing to do with optimizations, but rather with the way the languages are defined. For example, using the above y in a file-scope array type declaration is legal in C++, but not in C

     typedef int int_array[y]; /* OK in C++, ERROR in C */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Better yet, how can I make My Computer always open in Explorer as well?
I always believe they did, but seeing some answers here make me doubt... Can
I always seem to have a hard time starting a new Firefox extension. Can
Always was interested why are Array.Sort() and Array.IndexOf() methods made static and similar ArrayList.Sort()
Always when I run java application it will display in Windows Task Manager is
I always tend to forget these built-in Symfony functions for making links.
I always use unix timestamps for everything, but am wondering if there is a
I always felt that expecting exceptions to be thrown on a regular basis and
I always seem to use Get when working with data (strongly typed or otherwise)
I always have found the open source space interesting but have never actually participated

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.