Argument to function is declared as const, then Function can’t modify argument - Functions

Q.  If an argument to a function is declared as const, then _______ .
- Published on 17 Jul 15

a. function can modify the argument.
b. Function can’t modify the argument.
c. const argument to a function is not possible.
d. None of these

ANSWER: Function can’t modify the argument.
 

    Discussion

  • Nihal   -Posted on 09 Oct 15
    If an argument to a function is declared as const, then Function can’t modify the argument. . You can use const to prevent modifications to variables.
    Example:
    void fun(const int i)
    {
      i++;
    }
    The above function will give the error, because the variable i is constant, so you cannot do i++;

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)