char inputName[80] = {'\0'}; What does this do?

char inputName[80] = {'\0'};

i'm confused on what this line of code does. can someone explain?
It declares a character array with 80 elements and sets the first one to '\0', which is the NULL character.
'\0' is a character literal specified as an octal escape value. Its value is equal to 0.

The declaration

char inputName[80] = {'\0'};

means that the first element of the character array is explicitly set to zero that is to character literal '\0'. All other elements of the array also will be set to zero if there are no explicit initializers for other elements of the array. The same result you could get if you would write (only in C++)

char inputName[80] = {};

That is in the both cases all elements of the array will be initialized with 0.
Last edited on
The program prompts the user for a file but you don't really know how many elements are in the file so why did they use 80? when declaring the variable "inputname"

They simply decided that 80 is a reasonable value for the file name.:)
okay thank you so much!
Topic archived. No new replies allowed.