+ 1
what is this number for ?
#include <stdio.h> int main() { char a[ this number for?]; gets(a); printf("You entered: %s", a); return 0; }
4 Réponses
+ 3
char a[x] is array of characters and x determines size of that array
try x = 5 and type some longer string, in array will be stored just 5 characters from that string
+ 2
It is probably caused by gets() function, may it use next memory blocks and save whole string, and then ends it with \0 and function printf is printing all characters in memory until \0 (end of string character).
+ 1
I wanted to write the same answer as Matus.
Which theoretically is right
When I tried to write some sample code it does not work that way.
https://code.sololearn.com/cGGIj5G88kg0
Does anybody know why the output is
elephant ? and not ele
0
it is use to declare the length of the string, i.e the number of characters strings will store.
for example :-
char a[5] = {'R', 'A', 'H', 'U', 'L'};
here it's size is 5 if we define one more characters in then it will provide me some error.