Thread: Void, return... and what to use for 2D games?

  1. #1
    Registered User Kenoriga's Avatar
    Join Date
    Dec 2006
    Location
    Singapore
    Posts
    5

    Red face Void, return... and what to use for 2D games?

    Hello! Its my first post here in C Board... I have been using Cprogramming.com quite alot, and it really helped me, although there are still a coupla C codes I still don't understand, nor use.

    I have always been wondering, what is Void for, and return about.
    A.k.a
    Code:
    void hello();
    
    /* and */
    
    return 0;
    What does it mean when you "return a value" ?


    Also, I have a project, Tetris from my ex-teacher. Programming is not really a subject in my school, but an extra activity under a info-media club. I am trying to start with OpenGL, but stupid me, I can't really know what the different codes are about. Are there any recommended websites that do OpenGL in C(if there is, or Win32 if not), and also for 2D graphics? Or perhaps some new kinds, like SDL or whatever there are? Lol.

    Merry Christmas, and thank you!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    void function is a function that does not return a value

    return statement is used to return a value from the function and end its flow

    like:
    Code:
    int sumOfInts(int a, int b)
    {
       return a+b;
    }
    It can be used in the followint way:
    Code:
    int main()
    {
       int sum = sumOfInts(3,5);
       printf("sum of 3 and 5 is %d", sum);
       return 0;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Are there any recommended websites that do OpenGL in C
    OpenGl programming

    This is E-book. Which teaches you everthing about OpenGL

    ssharish2005

  4. #4
    Registered User Kenoriga's Avatar
    Join Date
    Dec 2006
    Location
    Singapore
    Posts
    5
    Oh, thank you both! ^_^.

    If its possible, just one last check ->

    Code:
    a = a + 1
    is not a return value, right?

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    did you mean something like this

    Code:
    void func(int a)
    {
        a = a+1;
    }
    this function doesn't return a value. but this does

    Code:
    int func(int a)   // not the return type which basically specifying that u are return a value of type int
    {
        return a = a+1;   //  in this case the expression will be evaluated first and the the value of 'a' will be returned. this statement can Else be written-ed as return a+b  as well
    }
    hope this helps


    ssharish2005

  6. #6
    Registered User Kenoriga's Avatar
    Join Date
    Dec 2006
    Location
    Singapore
    Posts
    5
    Ok. Thanks alot. It cleared up everything ^^

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Check out the tutorials, specifically, this one: http://www.cprogramming.com/tutorial/c/lesson4.html

    Though admittedly the only mention I can see of return values is this.
    When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four.
    For example:
    Code:
    #include <stdlib.h>   /* Include rand() */
    
    int a = rand(); /* rand is a standard function that all compilers have */
    Do not think that 'a' will change at random, it will be set to the value returned when the function is called, but it will not change again.

    The general format for a prototype is simple:
    Code:
    return-type function_name ( arg_type arg1, ..., arg_type argN );
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed