Thread: what is -29368 output in the below code

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    24

    what is -29368 output in the below code

    The code below prints -29368 as output at the end if I enter order of matrix 2 and 2 AND Value of matrix as 1,2,3,4

    I wonder what that -29368 refers to? is it memory address or anything else?

    Code:
    int matrix[3][3],i,j,n,c;
    clrscr ();
    printf ("Please enter the order of matrix\n");
    scanf ("%d and %d", &n, &c);
    printf ("The order of matrix you entered is &d and &d\n", n, c);
    printf ("please enter the value of matrix\n");
    for (i = 0; i<n; i++)
    for (j = 0; j<c; j++)
    scanf ("%d", &matrix[i][j]);
    printf ("So the matrix is \n");
    for (i = 0; i<n; i++)
    {
    for (j = 0; j < c; j++)
    printf ("%d \t", matrix[i][j]);
    printf ("\n");
    }
    printf ("%d\t", matrix[i][j]);
    getch ();
    return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    First of all... Learn to indent your code according to some consistent theme. You'll be amazed how many errors you can spot just by the way you set up the source code text... Conversely you'll be surprised how many errors are masked by code like you posted above.

    Ask yourself what are the values of i and j when you get to line 17...

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What value did you enter for n and c? If either of these values are larger than 2 you are writing, reading to values outside of the bounds of your array. Otherwise you are reading a value that was not initialized, so it could be holding anything.

    Jim

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    24
    Thanks CommonTater. I will learn slowly indentation also.
    @jimblumberg
    value of n is 2 and c is 2

    And line 17 is matrix[2][2] in original source.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So then at the end of your loops i and j will be equal to 3 and the following line:
    Code:
    [printf ("%d\t", matrix[i][j]);
    Edit: Sorry this would be accessing a value that has not been initialized. The i and j values would be 2.

    Jim
    Last edited by jimblumberg; 11-16-2011 at 04:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. output of following c code
    By shivakumar in forum C Programming
    Replies: 3
    Last Post: 05-05-2011, 07:44 AM
  2. what is the output of this code?
    By karthik537 in forum C Programming
    Replies: 15
    Last Post: 09-16-2009, 11:20 AM
  3. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  4. Output of code
    By lesodk in forum C++ Programming
    Replies: 5
    Last Post: 05-17-2009, 08:56 AM
  5. What will be the output of the following code?
    By developersubham in forum C++ Programming
    Replies: 13
    Last Post: 01-02-2007, 07:36 AM