The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+18 votes
2.3k views

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
asked in Programming by Veteran (59.9k points)
edited by | 2.3k views
0

5 Answers

+21 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.

answered by Active (4.9k points)
edited by
0
In sql aliasing means temporarily rename a table.same concept in c ?
+20 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=a*a;

A)multiple variables having the same memory location

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

This example also good http://www.cs.uregina.ca/Links/class-info/cplusplus/Standards/Disk10/aliasing_c.html

answered by Veteran (114k points)
0
@srestha Is your example for option (C) allowed in code?
0
why will it not allow?
+1

Try running this code- http://ide.geeksforgeeks.org/ccAyN2

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

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

Can we relate aliasing with the union?
+1

Example of multiple variables having the same identifier -

void fun1()
{
int t =10;  // local variable of function fun1.
printf("%d",t);
} 

void fun2()
{
int t=11;  // local variable of function fun2.
t= t+t;
printf("%d",t);
}

int main()
{
fun1();
fun2();
return 0;
}
+1

@Soumya

Can we define a pointer as a variable?

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

https://stackoverflow.com/questions/17643036/whats-the-difference-between-a-pointer-and-a-pointer-variable

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

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

right?
0

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

+1

@Srestha.
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?

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

That is not true I think
0
@srestha . Any counter example ?
+1
0
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.
0
@Soumya

actually variable and identifier refers to same in C programming

right?
+15 votes
A OPTION
answered by (473 points)
+1

Call by reference is the best example for that.

+1
we can relate to SQL query also...

SQL aliases are used to give a table, or a column in a table, a temporary name.
+1 vote
int i=10;
int *p=&i;
As long as p points to i,  we say that *p is an alias for i.
answered by Active (2.9k points)
0
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.
–5 votes
ans c)
answered by Loyal (5.2k points)
+1
Option a is more appropriate.
Answer:

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
49,427 questions
53,611 answers
185,914 comments
70,885 users