I am new to C and recently encountered this problem.
I have two pieces of code:
#include <stdio.h>
#include <string.h>
int main()
{
char x = 'a';
// char *y=&x;
printf("%ld\n", strlen(&x)); // output: 1
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char x = 'a';
char *y=&x;
printf("%ld\n", strlen(&x)); //output: 7
return 0;
}
What exactly happened when I added the variable y that it changed the result?