Why this code shows warning? In C | SoloLearn: Learn to code for FREE!


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/26/2020 2:47:45 PM


11 Answers

New Answer


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


Same reason, a[0] is already an address, & a[0] asks for the address of an address, and so it gives you a warning


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


Thank you very much Davide 😊


You are welcome πŸ€—


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]);


Thank you very much Davide πŸ˜ŠπŸ˜ƒ




Thank you very much Angelo 😊 But can you tell me,what is the meaning of warning, displayed in console....


Thank you Angelo 😊


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.....