i want to use float values inside the array for example,
array[4];
array[0] = 3.544
array[1] = 5.544
array[2] = 6.544
array[3] = 6.544
float array[] (is giving me error)
but i dont know how to use help me, i am a c beginner
i want to use float values inside the array for example,
array[4];
array[0] = 3.544
array[1] = 5.544
array[2] = 6.544
array[3] = 6.544
float array[] (is giving me error)
but i dont know how to use help me, i am a c beginner
You have to specify the size if you are going to define array float in this way:
float array[4];
You can define the array without the size. but it should be in this way:
float array[] = {3.544, 5.544, 6.544, 6.544};
see the following topic for more details: How to initialize all members of an array to the same value?
float array[4];
array[0] = 3.544;
array[1] = 5.544;
array[2] = 6.544;
array[3] = 6.544;
This should work buddy.
You can't create an array with no static size.
You can create an array like this on the stack, which is mostly when you have smaller arrays:
float myarray[12];
it is created in the scope and destroyed when that scope is left.
or you can create large arrays using malloc
in C, the are allocated on the heap, these need to be
manually destroyed, they live until you do so:
// create array dynamically in C
float* myheaparr = malloc(sizeof(float) * 12);
//do stuff with array
// free memory again.
free(myheaparr);
Specify number of elements you wanna work with while declaring.
float array[number of elements];
this will statically allocate memory for specified. Access each elements with index. eg
float array[4] will statically allocate memory for 4 floating point variables. array[0] refers to the first element and so on.