Option A is my answer.
Let us analyze.
"Aliasing" means more than one name for a memory location. If one address can be accessed by two or more "SYMBOLIC NAMES".
Most close option is OPTION A.
"multiple variables having the same memory location"
But, here we have to assume symbolic names to be the same as variable identifiers.
int *ptr;
int i;
/* &i : is a symbolic variable
*p: is a symbolic variable */
But only
/* i and p : are variables */
So, even though we can access the memory location &i, through two symbolic names, this is not the correct argument for OPTION A.
Now, taking the concept of UNION data type solves the issue.
#include <stdio.h>
int main()
{
union u
{
float f;
unsigned u;
} fu;
printf("The address of the variable fu.f : %p\n", &fu.f );
printf("The address of the variable fu.u : %p\n", &fu.u );
printf("The address of the variable fu : %p\n", &fu);
return 0;
}
Produces the output:
The address of the variable fu.f : 0x7fff764ceb84
The address of the variable fu.u : 0x7fff764ceb84
The address of the variable fu : 0x7fff764ceb84
So, option A has been proved. Here multiple variables are having same memory location.
Though , I would like to point out that the language of OPTION A has made some common aliasing examples ineligible for argument here:
1. Two pointers pointing to same memory location
2. Pointer to a variable, as both the pointer as well as the variable has access to same memory location
But the positive examples are:
1. UNION
2. ARRAY OVERFLOW
# include <stdio.h>
int main()
{
int arr[2] = { 1, 2 };
int i=10;
/* Write beyond the end of arr. Undefined behaviour in standard C, will write to i in some implementations. */
arr[2] = 20;
printf("element 0: %d \t", arr[0]); // outputs 1
printf("element 1: %d \t", arr[1]); // outputs 2
printf("element 2: %d \t", arr[2]); // outputs 20, if aliasing occurred
printf("i: %d \t\t", i); // might also output 20, not 10, because of aliasing, but the compiler might have i stored in a register and print 10
/* arr size is still 2. */
printf("arr size: %d \n", (sizeof(arr) / sizeof(int)));
}
Here also the LOCATION OF TWO VARIABLES:
1. arr[2], and
2. i
are same.