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

This is a discussion on initialisng an array of floats (float* array???) within the C Programming forums, part of the General Programming Boards category; What exactly does Code: float* variable; do, I think its a pointer to a float but I've seen it used ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    12

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

    What exactly does

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

    Code:
    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
    Location
    Singapore
    Posts
    21,326
    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.
    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,414
    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
    Posts
    12
    Ahhhhhhhh

    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

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