How do I find the length of an array?

前端 未结 27 2880
轮回少年
轮回少年 2020-11-21 23:10

Is there a way to find how many values an array has? Detecting whether or not I\'ve reached the end of an array would also work.

27条回答
  •  情书的邮戳
    2020-11-21 23:29

    Is there a way to find how many values an array has?

    Yes!

    Try sizeof(array)/sizeof(array[0])

    Detecting whether or not I've reached the end of an array would also work.

    I dont see any way for this unless your array is an array of characters (i.e string).

    P.S : In C++ always use std::vector. There are several inbuilt functions and an extended functionality.

提交回复
热议问题