Thread: killer functions

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    7

    Unhappy killer functions

    Hi:

    I am reading this book called "Teach yourself C". This book was published in 1990 and author's name is Osborn.

    He expalines the examples somehow very vague and difficult to understant. There must be a simple way to explain an example.

    1. This program prints 123 on the screen.

    /*This program has three fuctions.*/


    #include <stdio.h>

    main()

    {

    func2();

    printf("3");
    }

    func2()
    {
    func1();
    printf("2");

    }

    func1()
    {
    printf("1");

    }


    the explanation for this program accoring to author:

    In this program, main() first calls fuc2(),
    which then calls func1(). Next, func1() displays 1 and returns to fuc2(), which prints 2 and then returns to func2(), which prints2 and then returns to main(), which prints3.

    I am sorry , you senior programmers, might think how stupid I am.
    But the fact is, I am new to C and if this program had one function
    I do understand it, I think, this program will give the same result if it had only one function. After main (), it should be: {
    int num; num=123 then printf ("the value is %d", num");
    }

    but he has jump from one func to another and created a confusion. Is it OK, to read a C book that is 12 years old?

    Thank you

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    I think he wanted to explain that functions are executed sequentially (?), is that correct English?

    If in a function a second function is called, then that second function will be executed before the first function goes further.

    So

    Code:
    function_a ()
    {
      function_b ()
      printf ("a");
    }
    
    function_b ()
    {
      printf ("b");
    }
    has the same result as

    Code:
    function_a ()
    {
      printf ("b");
      printf ("a");
    }
    C has changed through the years, so perhaps it is better to get a new book on C, one which also contains the last C standard. I can remember that in old C books the notation

    Code:
    int function (a, b)
    int a;
    int b;
    was used. Currently we would do it like this

    Code:
    int function (int a, int b)
    And the last C standard has some nice things like variable arrays etc.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    7
    Thank you very much.It did help me alot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM