+ 1
Why this code shows warning? In C
I can't able to understand,the reason behind the warning, displayed by the console.... https://code.sololearn.com/cUWwDo18D45h/?ref=app
11 Respostas
+ 4
a[5][7] is an array of 5 arrays
You can refer to the first one like that:
&a[0][0]
That is a pointer to the first element of the first array, or even like that:
a[0]
because the name of an array is a pointer to it's first element.
If you write &a[0] you have a pointer to the first element of your array of arrays, i.e. a pointer to a pointer to char.
But %s is expecting just a pointer to char
+ 3
Same reason, a[0] is already an address, & a[0] asks for the address of an address, and so it gives you a warning
+ 2
scanf("%s") needs a memory address.
a[0] is a variable that holds a memory address
a[0] gives a value, that value is the memory address of your array
&a[0] gives a memory address, the memory address of a[0].
So, scanf("%s", a[0]) puts %s in the array
scanf("%s", &a[0]) puts the %s in a variable that is supposed to hold a memory address, not %s
So it gives you error
+ 1
Thank you very much Davide đ
+ 1
You are welcome đ€
+ 1
a is the name of the 2D array
a[0] is the name of the first array of the 2D array
Since an array name is a pointer to its first element, a = &a[0] and a[0] = &a[0][0]
scanf("%d", a); is the same of:
scanf("%d", &a[0]);
You can't do that, a is a pointer to a pointer to int, but %d expects a pointer to int
what you can do is
scanf("%d", a[0]); that is like:
scanf("%d", &a[0][0]);
+ 1
Thank you very much Davide đđ
+ 1
đ€
0
Thank you very much Angelo đ
But can you tell me,what is the meaning of warning, displayed in console....
0
Thank you Angelo đ