Calling function with arguments or noy

Hi Group,

I wanted to make a function that woukld need one argument,
but if there's no argument it should produce a default value on exit.
eg. FUNCTION(arg1) would exit something by using arg1 and
FUNCTION() should exit a value using a default arg1 inside the function.

int Function(char const *arg1) {
  char const *arg1 = __DATE__;
  return date += " a result";

But compiling this produces a error saying to few arguments.
How do I tell the compiler that this is correct??


What you can do is make 2 functions with the same name. One that takes an argument and another that takes no argument. Google "C++ function overloading".

You should be able to specify a default value in the function declaration.

you can also use a default argument value when there is none

output from my laptop using gcc

func: george
func: Mar 22 2021
#include <stdio.h>

func (const char *arg = __DATE__)
    printf ("%s: %s\n", __func__, arg);
    return 0;

main ()
    func ("george");
    func ();

    return 0;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.