When is there no need to write & in scanf ("%d",&a)?

When the input is an array, a itself is an address header. At this time, there is no need to add &, but adding & will not cause an error.

#include<iostream>
using namespace std;
int main()
{
    
    
    freopen("1.txt","r",stdin);
    //freopen("2.txt","w",stdout);
    char a[100] = {
    
    0};

    scanf("%s",a);

    printf("%s",a);

}

OR

#include<iostream>
using namespace std;
int main()
{
    
    
    freopen("1.txt","r",stdin);
    //freopen("2.txt","w",stdout);
    char a[100] = {
    
    0};

    scanf("%s",&a);

    printf("%s",a);

}

Everything is possible

Guess you like

Origin blog.csdn.net/dghcs18/article/details/103493686