"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 : Write a program that prints out all

    Write a program that prints out all prime numbers between 1 and 1000. Print the values out ten per line, with digits lined in proper columns.

  • Q : Explain Try statement Try statement :

    Try statement: The try statement performs as an exception handler - a position where exception objects are caught and dealt with. In its most common form, it comprises of a try clause, one or more catch clauses and the finally clause.

  • Q : Reading Algorithms Assignment 1:

    Assignment 1: Algorithms Rules: See the Assignment Rules file on the class Moodle site. 1 Reading Algorithms (20 points) Input: A nonempty string of characters S1S2 . . . Sn, and a positive integer n giving the number of characters in the string. Output: See t

  • Q : Does TestComplete maintain testing of

    Does TestComplete maintain testing of Flex applications?

  • Q : Aren't HTML Aren't HTML, SGML, and XML

    Aren't HTML, SGML, and XML all very similar things?

  • Q : Task decomposition and Data

    Discuss the idea of task decomposition and data decomposition within the perspective of parallel programming.

  • Q : Embedding C Code-Promela Embedding C

    Embedding C Code: Promela supports the use of embedded C code fragments inside the models through the use of the c_code primitive. 12_c code.jp</span></p>
                                        </div>
                                        <!-- /comment-box -->
                                    </li>
   
   </td>
	</tr><tr>
		<td>
       
      <li>
                                        <div class=

    Q : Explain Variable declaration Variable

    Variable declaration: It is the association of a variable with a specific type. It is significant to make a distinction among the declaration of variables of primitive types and such of class types. The variable of primitive type performs as a contain

  • Q : Main function of context switching What

    What is the main function of context switching?

  • Q : Illustrates database connection pooling

    Illustrates database connection pooling which is relative to MTS. Answer: This permits MTS to reuse database connections. Pooling of database connections are put to

©TutorsGlobe All rights reserved 2022-2023.