C sizeof char* array

后端 未结 3 1780
温柔的废话
温柔的废话 2020-12-14 00:33

I have a char* array as follows:

char *tbl[] = { \"1\", \"2\", \"3\" };

How do I use the sizeof operator to get t

3条回答
  •  无人及你
    2020-12-14 01:12

    Yes,

    size_t n = sizeof(tbl) / sizeof(tbl[0])
    

    is the most typical way to do this.

    Please note that using int for array sizes is not the best idea.

提交回复
热议问题