Thread: what is the best method of tracing this code on paper..

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Are you saying the rules are that there is guaranteed to be no trick code in there?

    Also, tmp will be at least 1, not at least 8 (all tho it will get at least as high as 6?)

    But witness the return value is not used anyway
    Code:
    what1(arr,6,5) ;
    meaning the intent is just to process the matrix, but like I said last time, I do not think any changes will be made in this "process".
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    why they do
    Code:
    if (tmp > stam)  stam = tmp;
    ??

  3. #18
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    So I compiled this code and added a function to check the matrix values before and after the function calls:
    Code:
    void show (int *ptr[], int r, int c) {
            int i, ii;
            for (i=0; i<r; i++) {
                    for (ii=0; ii<c; ii++) printf("%5d",ptr[i][ii]);
                    printf("\n");
            }
    }
    
    // used this way:
    show(arr,6,5);
    And my theory is correct, the matrix is not changed! You know what that means? The whole thing is bogus (what1 and what2 do not do anything).

    So why do "they" do this:
    Code:
    if (tmp > stam)  stam = tmp;
    Why not? It doesn't matter anyway, the return value is not used for anything.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #19
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i was asked what what1 returns
    that the whole purpose

  5. #20
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by transgalactic2 View Post
    i was asked what what1 returns
    that the whole purpose
    Yuck. I guess you will have to look at that loop containing (!j && !i) and decide how many times what2 gets called, because the return value of what1 would be the highest value from the nested for loop that calls what2 -- which the longest single recursive chain would be 5 or 6, except it looks like it might be called several times on each cell, so may 10, 12, or a bit more...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newton Raphson method code
    By taebin in forum C Programming
    Replies: 2
    Last Post: 10-17-2004, 02:44 AM
  2. Newton Raphson method code
    By taebin in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2004, 03:07 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM