Karma Doe Karma Doe - 2 months ago 8x
C Question

C var definition.

Simple question, I understand that C has no understanding of strings and it´s all just about arrays of numbers and characters.

I´ve been working with code in multiple languages and sometimes there´s something like this that´s easier to just ask for to someone who knows.

The question is:

char name [Number];

What does the [Number] stand for, limit in characters? Limit in bytes, bits?


Number specifies the number of elements in the array.

We can do:

char name[10];

To allocate 10 bytes, or something like:

#define Number 10

char name[Number];

This means you can store up to 10 characters, although the \0 sequence marks the end of a string - this tells other string handling functions where the end of the string is.

So techinally we can store 9 characters and the \0 to terminate the string.