Who is wrong, the book or me? (C two dimensional array) -


I read a book about C and there is an example in which the two-dimensional array and array of arrays .

The illustration in this book is:

  main () {ints [5] [2] = {{1234, 56}, {1212, 33}, { 1434, 80}, {1312, 78}}; Int (* P) ​​[2]; Int i, J, * Pint; (I = 0; i & lt; = 3; i ++) for {p = and [i]; Pint = p; Printf ("\ n"); For (J = 0; J & lt; = 1; J ++) printf ("% d", * (pint + j)); }}   

I created my version for this code and I saw that in the code of code he declared a [5] [2] array and I [4] [2] array and we have only one result.

Here's my code:

  #include & lt; Stdio.h & gt; Int main () {int arr [4] [2] = {0,1,2,3,4,5,6,7}; Int (* P) ​​[2]; Int i = 0, x = 0, * pint; Whereas (i and lt; = 3) {x = 0; P = & amp; Arrival [i]; Pint = p; I ++; While (x    

Both of you are wrong because:

  Pint = p;   

There is an error that your compiler should give at least warnings about this. The code should be:

  pint = * p;   

Your loop structure is hard to follow in comparison to the book, and you do not place any space between the numbers.

You think that from int arr [5] [2] to int arr [4] [2] . The original is not wrong You do not have to use every element of the array declared by you. The book had an array with 5 rows, but 4 of them is only good.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -