Like Tree1Likes
  • 1 Post By std10093

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

This is a discussion on int numb (char String[]) ??? what does this mean? within the C Programming forums, part of the General Programming Boards category; hi guys I'm new to arrays and officially have no idea of what this line means: Code: int numb (char ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    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.
    laserlight likes this.
    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
    21,445
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,675
    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, 04: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, 05:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21