Thread: compilation error on array assignment.

  1. #1
    Registered User
    Join Date
    Apr 2009

    compilation error on array assignment.

    Hi ALL,

    I have following code snnipet which gives error:

    int main()
    float arr[2][3] = {{0,1,2},{3,4,5}};
    float *fl_arr;
    fl_arr = arr;             //error -- line 1
    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
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    It is not, because it is a 2D array. Proper would be:
        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