How do you set i<= array length

Hello, how do you stop the iteration when it has reached the array length?

#include <iostream>
#include <cmath>
using namespace std;

int main(){

int b[]={1,2,3,4,5,6,7};

for(int i=0; i<=array.length; i++){ //instead of array.length?
cout <<b[i]<<", ";

int c;

Last edited on
Universal way for constant arrays. Works for c also:
#define arrlength(x) sizeof(x)/sizeof(x[0])
because sizeof is rather also precompiled macros result will be as fast as possible because on compilation stage you will get exactly constant
Thanks, what do you write in the code?
    int array[]={1,2,3,4,5,6,7};
    const int length = sizeof(array) / sizeof(array[0]);

or possibly use std::vector instead.
Last edited on
Topic archived. No new replies allowed.