Forum

Default Parameters In C++

This thread contains 1 reply, has 2 voices, and was last updated by Test 4 years, 11 months ago.

  • Author Replies
    • #62386

      What are the Default Parameters? How are they evaluated in the C++ function?


    • #62387

      Hello,

      A default Parameter is a value provided in a function declaration that is automatically assigned by the compiler if the caller of the function doesn’t provide a value for the argument with a default value.

      Let me elaborate Default parameter with One Example So you can get a better idea about it!

      #include

      // A function with default arguments, it can be called with
      // 2 arguments or 3 arguments or 4 arguments.
      int sum(int x, int y, int z=0, int w=0)
      {
      return (x + y + z + w);
      }
      int main()
      {
      cout << sum(10, 15) << endl;
      cout << sum(10, 15, 25) << endl;
      cout << sum(10, 15, 25, 30) << endl;
      return 0;
      }

      OutPut:
      25
      50
      80


Viewing 1 reply thread

You must be to reply to this thread.Please or . Registration is 100% free.

GET FREE CONSULTATION

Call Us Now For Free Consultation97370 05566

Our experts listen to you patiently and suggest you the right course after conducting a personality profile test. Register your interest below to schedule personality profile test for you.

SUBSCRIBE TO OUR NEWSLETTER

Subscribe to get latest updates regarding courses, IT industry and career prospects.

Copyright 2016-2024 Smart Mentors. All Rights Reserved.

Login

FORGOT PASSWORD

Sign up now to Become An Instructor

    Register your Interest

      cf7captchaRegenerate Captcha