Thread: initialisng an array of floats (float* array???)

  1. #1
    Registered User
    Join Date
    Dec 2008

    initialisng an array of floats (float* array???)

    What exactly does

    float* variable;
    do, I think its a pointer to a float but I've seen it used like an array!

    for(i=0; i<512; i++)
    	variable[i]= 0.0;	                    	
    Is this dangerous? There is no specfic array size??? So you could write over memory already being used etc.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Assuming that the pointer does not actually validly point to something, then yes, it would be dangerous and results in undefined behaviour. Of course, if it points to the first element in an array of at least 512 floats then it would be perfectly fine.
    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
    Pointers can use array syntax, since it will work the same way arrays are handled.
    Again, note that pointers are not arrays. Once you properly understand pointers, you will see how they can be used as arrays.
    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
    Dec 2008

    Thank you now I see.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem when qsorting an array of floats
    By avi2886 in forum C Programming
    Replies: 8
    Last Post: 04-30-2009, 02:46 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM