0

There is a function:

void fnc (T arg[]) {

    // inside the function there is something like this:
    // A = B + arg[index] * C;
}

In some situations, there is nothing to pass so, arg[] should be zero. So, is there a way to call function as this way: void fnc(0);?

3
  • T * arg would be clearer in this case. Commented Feb 18, 2012 at 17:15
  • 3
    passing an array with all elements 0 is not the same as passing a reference to an empty array. Commented Feb 18, 2012 at 17:19
  • So, what do you really want - pass array with all elements = 0 or pass empty array? Commented Feb 18, 2012 at 17:56

1 Answer 1

4

In that case you can call function will null value e.g : fnc (NULL); . But make sure to check in function whether arg == NULL or not before using it.

P.s: Best thing is to use std::vector instead of simple array.

Sign up to request clarification or add additional context in comments.

3 Comments

Did you change the function argument to T* arg and are you really checking for the case arg==NULL?
@Shibli check this: ideone.com/GDUCz, you can pass NULL or 0 ,since NULL is macro defined 0, What compiler you're using?
@Mr.Anubis: I have checked the link. Compiler is Intel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.