Find answers, ask questions, and connect with our <br>community around the world.

  • Posted by TAPAS KUMAR PRADHAN on August 25, 2022 at 1:21 pm

    Dear sir, I have some doubts regarding the second assignment.
    For int a = 3.14.

    While using flags “-Wall” and “-Wall -Werror” , I got the executable file in both cases and along with that I did not receive any warning message The output in both cases was 3 instead of 3.14.
    As per your lecture “-Wall -Werror” should not give any executable file.

    For const int a = 10.

    While using flags “-Wall” and “-Wall -Werror” both cases I did not get any executable files.
    As per your lecture “-Wall ” should give one executable file with some warning message.
    Please clarify my doubts in this regard

    Nishant replied 1 year, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Nishant

    Member
    September 6, 2022 at 12:02 pm

    Dear Tapas,

    The recent versions of C++ have the ability to perform dynamic implicit type-casting. Therefore, they will allow statements like,
    int a = 3.14
    This is done mainly to make life easy for programmers but as you can see that the value printed on the screen for a is 3 and not 3.14 because a is declared to hold an integer value.

    When you declare a variable with const keyword, C++ will not allow any further re-assignment. Anything declared with const keyword provides read-only access and it can not be overwritten with any new value. Because reassignment is not semantically correct for any const type variable, it will not produce any executable file.

Log in to reply.

error: Content is protected !!