My teacher told us to use "&" in order to store values to our desired variables however, I tried to use scanf() and I tried to store values to some variables without the "&" and I noticed that it still works just fine? Is it affecting my code in anyway despite me thinking that it didn't?
Here are the codes that I have tried. The code is a part for checking whether the second input is a substring. The original form which is taught by my teacher:
int main(){
char word1[100], word2[100];
int length1, length2;
printf("Enter the a word: \n");
scanf("%s", &word1);
printf("Enter the potetial substring: \n");
scanf("%s", &word2);
for(length1=0; word1[length1]!='\0'; length1++);
for(length2=0; word2[length2]!='\0'; length2++);
if (length1<length2)
{
printf("Second input is not a substring.\n");
}
Then I tweaked the part where the program asks for inputs to this:
printf("Enter the a word: \n");
scanf("%s", word1);
printf("Enter the potetial substring: \n");
scanf("%s", word2);
I still got the same output even if I removed "&". Hopefully someone can explain if this change is affecting my codes in some way that I may not be aware of, thank you.