"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 : Define Finally clause Finally clause :

    Finally clause: This is a part of try statement which is always executed, either subsequent the handling of caught exception, and normal termination of the protected statements.

  • Q : Recursive Matlab function Write a

    Write a recursive Matlab function TriUVRCol that solves a virtually upper triangular system of equations accessing the matrix by column. Write another recursive Matlab function LUPivRec that recursively computes the LU decomposition of a matrix using partial pivoting.

  • Q : Determine incorrect tags in HTML What

    What is incorrect with my < br > Tags?

  • Q : Explain the steps to design product If

    If not in production, how far did you obey the design and why did not you notice it in production?

  • Q : CORBA allows high performance

    'CORBA was designed to allow high performance distributed applications to be written’. Discuss. Definitely, ’CORBA was designed to allow high performance distributed applications to be written’ because it provides:

  • Q : Explain Exclusive-or operator

    Exclusive-or operator: An exclusive-or operator (^) is both a Boolean operator and the bit manipulation operator. The Boolean version provides the value true when only one of its operands is true; or else it offers the value false. Likewise, the bit m

  • Q : Program and process Explain the term

    Explain the term program and process?

  • Q : Explain Constructor Constructor : A

    Constructor: A constructor is automatically called whenever an instance of its class is formed. A constructor always has similar name as its class, and encompass no return type. For example: public

  • Q : Program for Linux operating system that

    Write a program for Linux operating system that uses Posix threads to sort a large array.  Specifically, you should write a program to generate random numbers. Then create at least two threads, each of which sorts a portion of the array. After the thr

  • Q : Define Permission Normal 0 false false

    Normal 0 false false

©TutorsGlobe All rights reserved 2022-2023.