To declare a float array in C++, you can use array notation or the standard library vector.
In this example,
floatArray
with predefined values using array notation.#include <iostream>
#include <vector>
int main() {
float floatArray[] = {1.2, 3.4, 5.6};
int size = sizeof(floatArray) / sizeof(floatArray[0]);
std::cout << "Float Array: ";
for (int i = 0; i < size; ++i) {
std::cout << floatArray[i] << ' ';
}
std::cout << '\n';
return 0;
}
Float Array: 1.2 3.4 5.6
In this example,
emptyFloatArray
using the standard library vector without any elements.#include <iostream>
#include <vector>
int main() {
std::vector<float> emptyFloatArray;
std::cout << "Empty Float Array: ";
for (float val : emptyFloatArray) {
std::cout << val << ' ';
}
std::cout << '\n';
return 0;
}
Empty Float Array:
In this tutorial, we learned How to Declare a Float Array in C++ language with well detailed examples.