Help me with Array and Pointer confusion.

This is a discussion on Help me with Array and Pointer confusion. within the C Programming forums, part of the General Programming Boards category; If the following is possible: Code: MyFunction(int *array, int size) { for(int i=0 ; i<size ; i++) { printf(%d, array[i]); ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Help me with Array and Pointer confusion.

    If the following is possible:

    Code:
    MyFunction(int *array, int size)
    {
    	for(int i=0 ; i<size ; i++)
    	{
    		printf(%d, array[i]);
    	}
    }
    
    main()
    {
    int array[] = {0, 1, 2, 3, 4, 5};
    	MyFunction(array, 5);
    }
    Why the following is not?
    Code:
    MyFunction(int **array, int row, int col)
    {
    	for(int i=0 ; i<row ; i++)
    	{
    		for(int j=0 ; j<col ; j++)
    {
    			printf(%d, array[i][j]);
    }
    	}
    }
    
    main()
    {
    int array[][] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    	MyFunction(array, 3, 3);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    That is not the thing I asked for.

    Quote Originally Posted by Elysia View Post

    That is not the thing I asked for.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    But it is something you need to fix.

    Expect all aspects of your code to get crawled over and commented on, not just the bit you're having problems with.

    It's something you need to get used to if you start working in any multi-person programming environment, be it work or open source.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by edurazee View Post
    That is not the thing I asked for.
    If you want help here, then you are going to have to fix what is pointed out. If you don't have will to en such a simple thing, then we have no will to help you out. Accept it or leave.

    Written from my Nokia N8.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Location
    China
    Posts
    12
    Code:
    int array[][] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    It's grammatically incorrect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21