compilation error on array assignment.

This is a discussion on compilation error on array assignment. within the C Programming forums, part of the General Programming Boards category; Hi ALL, I have following code snnipet which gives error: Code: int main() { float arr[2][3] = {{0,1,2},{3,4,5}}; float *fl_arr; ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    139

    compilation error on array assignment.

    Hi ALL,


    I have following code snnipet which gives error:

    Code:
    int main()
    {
    float arr[2][3] = {{0,1,2},{3,4,5}};
    float *fl_arr;
    fl_arr = arr;             //error -- line 1
    fl_arr++;
    getch();
    return 0;
    }

    Why does it give compilation error? Isn't "error -- line 1" a valid statement?

    Thanks in advace

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,894
    What are you trying to do? It looks like you are trying to get a pointer to float to point to an array of float, which does not quite make sense.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,775
    It is not, because it is a 2D array. Proper would be:
    Code:
        float (*fl_arr)[3] = arr;
    Because the compiler needs to know the size of the outer dimension in order to properly calculate where to save and read data in the array.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning an object with a dynamic pointer
    By maxsthekat in forum C++ Programming
    Replies: 11
    Last Post: 09-16-2009, 01:52 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. array assignment question
    By threahdead in forum C Programming
    Replies: 2
    Last Post: 08-17-2003, 05:36 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

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