in Programming edited by
32 votes

Aliasing in the context of programming languages refers to

  1. multiple variables having the same memory location
  2. multiple variables having the same value
  3. multiple variables having the same identifier
  4. multiple uses of the same variable
in Programming edited by

1 comment

Subscribe to GO Classes for GATE CSE 2022

8 Answers

39 votes
Best answer

Option is A.

In computer programmingaliasing refers to the situation where the same memory location can be accessed using different names. For instance, if a function takes two pointers A and B which have the same value, then the name A aliases the name B.

edited by


In sql aliasing means temporarily rename a table.same concept in c ?


is sql a programming language as mentioned in the question?



there is no programing language mentioned in the question.


For instance, if a function takes two pointers A and B which have the same value, then the name A aliases the name B.

Can you give a code snippet for the above statement as it will make it more clear .

35 votes

B)multiple variables having the same value

int a=24;
int b=24;
int c=24;

 C)multiple variables having the same identifier

int a=23;
char a='A';

D)multiple uses of the same variable

int a=23;

A)multiple variables having the same memory location

int a=20;
int *p=&a;

This example also good


@srestha Is your example for option (C) allowed in code?
why will it not allow?

Try running this code-

yes, it is giving error because C doesnot allow multiple variable with same name

it is the example, what option C) is telling
As far as I know option (C) can't be implemented in real. Correct me if I am wrong.
Two pointers pointing to the same memory location is a good example of aliasing.

Can we relate aliasing with the union?

Example of multiple variables having the same identifier -

void fun1()
int t =10;  // local variable of function fun1.

void fun2()
int t=11;  // local variable of function fun2.
t= t+t;

int main()
return 0;


Can we define a pointer as a variable?

In question they are asking just for a variable and not pointer

@Srestha..Yes, we can define. Pointer is just a variable that can hold address of another variable.

why r u relating union here?

"A union is a variable that may hold (at different times) objects of different types and sizes,"

but union is not about same memory location


do u mean. in union for a highest memory location , a memory will be created,

but in structure,we need to create memory for every variable

like told here


Aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program.
Now I meant to say that-
Consider this union.

union { 
        float y; 
        long z; 
    } u;

Here 8 Bytes of memory will be allocated for it. Say from 1000 to 1008.
Now we can access this memory location using &u.y and &u.z.

So can we say it aliasing?

do u mean union always operate on the concept of aliasing?

That is not true I think
@srestha . Any counter example ?
i think union always operate on the concept of aliasing just the issue is that obviously we cannot access the value assigned to the variable by some other variable with distinct data type.

actually variable and identifier refers to same in C programming

15 votes


Call by reference is the best example for that.

we can relate to SQL query also...

SQL aliases are used to give a table, or a column in a table, a temporary name.
C Programming Language does not allow call by reference.


is sql a programming language as mentioned in the question? SQL (Structured Query Language) is a database management language for relational databases. SQL itself is not a programming language.

Though for argument's shake one may include it as programming language which maybe valid, but the spirit of the question is against it.

2 votes
int i=10;
int *p=&i;
As long as p points to i,  we say that *p is an alias for i.


You sure? Because if i has a memory location 100 then p will point to i but p can have a different memory location, say 200.

@Sambhrant Maurya

yes and for Option A to be true by this argument, variables here are

1. i

2. p

only. And clearly,

" multiple variables having the same memory location " (option A)

is not the case here. Though the, memory location

&i can be accessed by two ways :
&i and *p.

Logic of UNION gives OPTION A. Not this argument


2 votes

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:



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


1. arr[2], and

2. i

are same.


1 comment

As the answer is already long. Here I am commenting why OPTION C is wrong despite having many supporters here.

Yes, a variable identifier can be used multiple times in a program as we have the concept of scope. Multiple variables with same name may exist but they all would have different locations and are all essentially different.

/* global variable x */
int x ;
int x = 10;
int x;
all these 3 lines represent same variable in memory
line 2 : declaration
line 3: definition and initialization
line 4: forward declaration
/* global variables are stored in global symbol table of c compiler */
void printing()
	printf("Address of GLOBAL x: %p\n", &x);

void printing_local_x()
	/* local variable x*/
	int x = 11;
	/* definition + initialization */
	printf("Address of LOCAL_2 x: %p\n", &x);

int main()
    /* local variable x*/
    int x;
    /* int x = 11; wrong */
    /* local variables are STACK VARIABLES and can only be defined/declared once */
    printf("Address of LOCAL x: %p\n", &x);
    return 0;

The output is:

Address of GLOBAL x: 0x5592945a0010
Address of LOCAL x: 0x7fff9cce20b4
Address of LOCAL_2 x: 0x7fff9cce2094


0 votes

I know this question was asked in 2000 but if asked again its answers would be different, 

Correct answers would be A and C,

 A is called pointer aliasing(C) and C is called (Aliasing or Symbolic Aliasing, like in RUST) 

0 votes
A because aliasing  in programming context refers to same memory mapped to different name i.e access can be done to same memory via different names
–5 votes
ans c)

1 comment

Option a is more appropriate.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true