D
D
Dmitry Popov2017-10-13 17:08:42
C++ / C#
Dmitry Popov, 2017-10-13 17:08:42

Why is it displaying extra characters?

If I set an array 'butt' , then when displaying its contents, it displays extra characters on the screen

char L[4] = {'a','b','c','d'};
printf("%s\n", L);

conclusion: 59e0c8d35c1fd283623535.png
Why does he actually display them?
And is there any way to fix this without increasing the size of the array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-10-13
@DigitalLev

It should be 0 at the end. Like this: Or like this:
char L[] = {'a','b','c','d', '\0'};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question