Question:

How is a function with char array return type declared in C?

by  |  earlier

0 LIKES UnLike

How is a function with char array return type declared in C?

 Tags:

   Report

3 ANSWERS


  1. Ok, since you've asked about the declaration and not definition, here is how a function with char array as a return type is declared:

    char* foo(arg..);

    (where *arg* is the argument you want to pass to this function. In case of no argument, it won't be needed over there.)

    As for the example of how to define a char array returning function. here is an example of that sort, for your help:

    /* Program for returning no. of names from database */

    char list[10];   //global declaration of the character array.

    char* foo(int number);

    int main() {

    ......

    }

    char* foo(10) {

    /*sort & read names */

    return list;

    }

    hope that this will quench your search for the answer :)


  2. You can do this:

    char* myfunc(int x);

    Or this:

    char[] myfunc(int x);

    To answer the question I assumed you want a function that takes one int, and retuns a char array.  If the input args are different, modify accordingly.  For example: char* myfunc(); -- if there are no input args.


  3. char somefunction(<parameters>) {

    }

    just like any other function

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.