Thread: default values

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    3

    default values

    Give an example to illustrate the use of default values. Does it make compiling more efficient? Does it make the object code shorter? Why do we use it?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,619
    Give an example to illustrate the use of default values.
    istream::getline() behaves differently depending on what arguments are passed. Specifically, if you pass a third argument, that character becomes what the function looks for in order to stop reading. I recommend you read the manual about it.

    One way to implement all of these behaviors is to use default values in the implementation:
    Code:
    istream& getline (char* s, streamsize n, char delim = '\n');
    Another reason to use default values is if you are already using a function, but need to add more features. By using default values, you are not breaking code where the function was called the original way.
    Does it make compiling more efficient? Does it make the object code shorter?
    There is no real evidence it does any of these things... but if you use default values instead of function overloads, you will have implemented one less function - so the object code is smaller. If you ask me, using this as a reason for a design is missing the point. The good reasons are things I mentioned earlier in this post.

  3. #3
    Registered User
    Join Date
    Mar 2016
    Posts
    5
    hi,

    i am new in programming world so please explain in detail, are you in asking for variable default values ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input showing as default values
    By worl4125 in forum C++ Programming
    Replies: 3
    Last Post: 12-01-2013, 11:27 AM
  2. default values for Struct elements
    By udaraliyanage in forum C Programming
    Replies: 2
    Last Post: 04-09-2011, 06:17 AM
  3. default values in struct
    By taurus in forum C Programming
    Replies: 1
    Last Post: 10-04-2009, 05:43 AM
  4. variable default values
    By dasmann in forum C++ Programming
    Replies: 12
    Last Post: 09-26-2007, 02:21 AM
  5. Default values in function prototypes
    By wdicks in forum C Programming
    Replies: 13
    Last Post: 10-10-2001, 01:06 AM

Tags for this Thread