Functions in C language

Discussion in 'Programmer's Corner' started by circuit2000, Apr 26, 2007.

  1. circuit2000

    Thread Starter Active Member

    Jul 6, 2006
    In one of my exams the following question was asked:
    # List the 4 types of functions in C.
    Here are they referring to the 4 library functions in C namely math.h,string.h,stdio.h & stdlib.h?
  2. Papabravo


    Feb 24, 2006
    I don't think so, since there are more different kinds of header files than there are cross ties on the railroad tracks. I think it relates to return value and arguments.
    Code ( (Unknown Language)):
    2. [B]void[/B] function_type_1([B]void[/B])  //No arguments, No return value
    3. [B]void[/B] function_type_2([B]char[/B])  //1 argument, No return value
    4. [B]char[/B] function_type_3([B]void[/B])  //No arguments, Returns a char
    5. [B]char[/B] function_type_4([B]char[/B])  //1 argument, Returns a char
    Each of these function types would cause a compiler to generate different prologues and epilogs. If you don't know what those are, they are the instructions just before and just after a function call.
  3. Dave

    Retired Moderator

    Nov 17, 2003
    To be fair that question is as ambiguous as can be. Depending on your interpretation, one could argue there are only two types of function in C: user defined functions (i.e. those that you write) and library functions. Then the type can be sub-divided further in the way Papabravo has specified above, and in a similar way you have in your OP.

    If I received that question in an exam, I would probably be pretty miffed unless the lecturer had told me explicitly during the course that the 4 types of function in C are A).... B).... C).... and D)....