Q:

Error when returning character array from function, C++

I'm writing a sketch for the Arduino board and am using the following C++ code to do so. I'm trying to convert decimal numbers to binary by passing a decimal through the dec2bin function which is to return a character array that I will then print out. However, I'm getting the error: 
"Incompatible types of assignment of 'char' to 'char [0]'"
at the function call to dec2bin and I'm receiving another error at the return inside of the dec2bin function that says:
"Invalid conversion from 'char*' to 'char' [-fpermissive]"
If anyone could please assist me with this it would be greatly appreciated. I need to use a character array here and not a string! Thank you!
void loop() {
// put your main code here, to run repeatedly:
 if (Serial.available() > 0){
    char BinaryNum [0];
    int Decimal = Serial.parseInt();
    BinaryNum = dec2bin(Decimal);
    Serial.println (BinaryNum);

 }

}

char dec2bin (int Decimal){

  int Remainder; // Remainder of Decimal%2
  char Binary [0]; // Character array returned by dec2bin
  int x = 0;

  while (Decimal != 0 ){
    Remainder = Decimal%2; 
    Decimal = Decimal/2;
    Binary[x] = Remainder; 
    Serial.println(Binary[x]);
    x+=1;
  }

  return Binary;
}

A:

Danger Danger, you're returning a pointer to a local variable, Binary, that is on the stack, once the function returns it is out of scope and no longer valid.  This will cause weirdness, it will work some times and then it will stop working, don't do it!
See Can a local variable's memory be accessed outside its scope?
You need to pass in the storage.
eg.
void loop() {
// put your main code here, to run repeatedly:
 if (Serial.available() > 0){
    char BinaryNum[33]; // allows for 32 bits plus null terminator
    int Decimal = Serial.parseInt();
    dec2bin(Decimal, BinaryNum);
    Serial.println (BinaryNum);

 }

}

void dec2bin (int Decimal, char* Binary){

  int Remainder; // Remainder of Decimal%2
  int x = 0;

  while (Decimal != 0 ){
    Remainder = Decimal%2; 
    Decimal = Decimal/2;
    Binary[x] = Remainder; 
    x+=1;
  }
  Binary[x] = '\0';
}

On a "real" computer with an operating system there are many more memory management options than on a little arduino.  You could allocation from the heap and use something fancy like an auto_ptr to manage it (see What is a smart pointer and when should I use one?).
This just isn't possible on something as small as an arduino.   You could however allocate it as a static.  This isn't appropriate for a fancy computer because it is not re-entrant and thus not thread safe.  Static allocation is done at program linking or startup and persistent across calls.
void loop() {
// put your main code here, to run repeatedly:
 if (Serial.available() > 0){
    int Decimal = Serial.parseInt();
    char* BinaryNum  = dec2bin(Decimal);
    Serial.println (BinaryNum);

 }

}

void dec2bin (int Decimal) {
  static Binary[33]; // allows for 32 bits plus null terminator

  int Remainder; // Remainder of Decimal%2
  int x = 0;

  while (Decimal != 0 ){
    Remainder = Decimal%2; 
    Decimal = Decimal/2;
    Binary[x] = Remainder; 
    x+=1;
  }
  Binary[x] = '\0';

  return Binary;
}

