+ 3
because 'c', when used without an index as it is, is considered a pointer (or simply the array's starting place in memory) to the first value in the array. when you use for instance, &<a variable with a single peice of data (ex. int n; scanf("%d", &n;))> you are really accessing the memory location of that variable. So, in short, you dont use the & before 'c' in this case because 'c' is ALREADY a pointer (memory address)
15th Jul 2021, 4:35 PM
Slick
Slick - avatar
+ 3
In case of a string (character array), the variable itself points to the first element of the array in question. Thus, there is no need to use the '&' operator to pass the address. '&' is used to get the address of the variable. src:- https://www.google.com/amp/s/www.geeksforgeeks.org/not-used-strings-scanf-function/amp/ Any example code to what @Slick and I mentioned. https://code.sololearn.com/cc6e9RnbX38D/?ref=app
15th Jul 2021, 4:35 PM
minirkk
minirkk - avatar
+ 1
Verstappen name is an array of characters which means its a "string", so you will need to do for it to be valid. printf("%s", name); %s is for string (or array of characters). %c is for a single character. *name = name[0] *(name + 1) = name[1] And we know both are a single character and hence this works printf("%c", *name); displaying the name[0] which is "s" in our example.
16th Jul 2021, 8:09 AM
minirkk
minirkk - avatar