Thread: int numb (char String[]) ??? what does this mean?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    25

    int numb (char String[]) ??? what does this mean?

    hi guys

    I'm new to arrays and officially have no idea of what this line means:

    Code:
    int numb (char String[])
    what kind of idea does it give you? I've learned an array could look something like

    Code:
    string[2]= {1,3}
    for instance

    but what it means when it's an argument of some int variable?(variable here is numb)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > int numb (char String[])
    It says
    - numb is a function,
    - it takes a single parameter which has the name String, and it is an array of characters (actually, it will be a pointer),
    - it returns an integer result.
    If you know about strlen(), then you know how to use it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I would guess that he is a beginner in functions and probably haven't heard of strlen.

    A function's prototype has the following format :
    arg stands for argument
    Code:
    returnValue functionName(typeOfArgOne argOne, typeOfArgTwo argTwo, ...);
    Let's have some examples of function's prototypes (declarations).
    Example No. 1
    A function named foo, that returns an integer and has as argument an integer.
    Code:
    int foo(int number);
    Example No. 2
    A function named foo2, that returns an integer and has as argument two integers.
    Code:
    int foo2(int a, int b);
    Example No. 3
    A function named foo3, that returns an integer and has zero arguments.
    Tip : When no arguments are needed, we write void.
    Code:
    int foo3(void);
    Example No. 4
    A function named foo, that returns nothing and has as argument an integer.
    Tip : We write void as return value.
    Code:
    void foo4(int number);
    Example No. 5
    A function named foo5, that returns an integer and has as argument a character.
    Code:
    int foo5(char c);
    Example No. 6
    A function named foo6, that returns an integer and has as argument an array of characters (thus a word, a string).
    Code:
    int foo6(char String[]);
    Hope this helps a bit.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by std10093
    Example No. 6
    A function named foo6, that returns an integer and has as argument an array of characters (thus a word, a string).
    Code:
    int foo6(char String[]);
    The parameter in this case is actually a pointer to char, but because an array is converted to a pointer to its first element when passed as an argument, you can thus pass an array as the argument to foo6.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Thanks laserlight for pointing that out!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-02-2012, 05:25 AM
  2. Replies: 11
    Last Post: 06-16-2011, 11:59 AM
  3. Replies: 2
    Last Post: 09-12-2010, 09:15 AM
  4. Gen. Rand. numb.s
    By Dkunsberg in forum C++ Programming
    Replies: 31
    Last Post: 07-01-2005, 06:19 PM
  5. biased random numb generation
    By estranged in forum C Programming
    Replies: 4
    Last Post: 12-13-2003, 06:00 AM