"Const" qualifier for pointers and member function

In C++ an arguments to a function can be declared as constant as shown below:

Int strlen (constant char * p);

Int length (constant string & s);

The qualifier const tells the compiler that the function should not modify the arguments. The compiler will produce error when this situation is violated. This type of declaration is significant only when we pass arguments by reference or pointer.

Constant member functions: If a member function does not alter any data in the class, than we have may declare it as a constant member function as follows:

Void mul (int. Int) constant;

Double get _ balance constant;

The qualifier constant is appended to the function proto types (in both declaration and definition). The compiler is as a constant will generate an error message if such functions try to alter the data values.

 

 

 

   Related Questions in Programming Languages

  • Q : Protocol stack of XML Web Services

    Explain the protocol stack of XML Web Services.

  • Q : Rings present in CPU What do you mean

    What do you mean by rings present in CPU?

  • Q : Differentiate between RDO and ADO

    Differentiate between RDO and ADO?

  • Q : Define Thread starvation Thread

    Thread starvation: It is a condition which applies to a thread which is prevented from running by other threads which do not yield or turn into blocked.

  • Q : Define Object serialization Object

    Object serialization: The writing of an object's contents in such a manner that its state can be restored, either at a later time, or in a different procedure. This can be employed to store objects between runs of a program, or to transfer or shifts o

  • Q : Define the term Statement terminator

    Define the term Statement terminator: The semicolon (;) is employed to point out the end of a statement.

  • Q : Define the term XQuery Define the term

    Define the term XQuery?

  • Q : State Cout and Cin Cout: This is an

    Cout: This is an object of ostream_withassign class stated in iostream.h header file

  • Q : Examples of applications which can

    Give some examples of applications which can benefit from using XML?

  • Q : File handling modes and corresponding

    Discover Q & A

    Leading Solution Library
    Avail More Than 1453875 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering

    18,76,764

    1929130
    Asked

    3,689

    Active Tutors

    1453875

    Questions
    Answered

    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.