+ 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

26th Nov 2020, 2:47 PM
Yogeshwaran P
Yogeshwaran P - avatar
11 ответов
+ 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
26th Nov 2020, 3:53 PM
Davide
Davide - avatar
+ 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
26th Nov 2020, 2:57 PM
Angelo
Angelo - avatar
+ 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
26th Nov 2020, 3:39 PM
Angelo
Angelo - avatar
+ 1
Thank you very much Davide 😊
26th Nov 2020, 4:00 PM
Yogeshwaran P
Yogeshwaran P - avatar
+ 1
You are welcome 🤗
26th Nov 2020, 4:01 PM
Davide
Davide - avatar
+ 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]);
26th Nov 2020, 4:29 PM
Davide
Davide - avatar
+ 1
Thank you very much Davide 😊😃
26th Nov 2020, 4:34 PM
Yogeshwaran P
Yogeshwaran P - avatar
+ 1
🤗
26th Nov 2020, 4:35 PM
Davide
Davide - avatar
0
Thank you very much Angelo 😊 But can you tell me,what is the meaning of warning, displayed in console....
26th Nov 2020, 3:00 PM
Yogeshwaran P
Yogeshwaran P - avatar
0
Thank you Angelo 😊
26th Nov 2020, 3:46 PM
Yogeshwaran P
Yogeshwaran P - avatar
0
Davide and Angelo ,I have a another doubt😅Can you tell me , what does the "a" indicates in this below function...... I mean,it point's to,arrays which first element? scanf("%d",a);//in two dimensional array And also tell me difference between a[0] && a in two dimensional array.....
26th Nov 2020, 4:04 PM
Yogeshwaran P
Yogeshwaran P - avatar