GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 425 of 433    Print  
Difference between reference and pointer?
what is difference between reference and pointer or pass by reference and pass by pointer?


  
Total Answers and Comments: 1 Last Update: July 20, 2008     Asked by: janhavibend 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 20, 2008 01:05:06   #1  
rocky2583 Member Since: July 2008   Contribution: 3    

RE: Difference between reference and pointer?
In C there is no concept of a reference variable.
Only pointers exist. When you pass address of any variable to a function, it is termed as pass by reference. Coz the formal parameter in function is the pointer that stores this address.

In C++, reference variables exist. A reference variable does not get any memory of its own. It must be initailzed when it is declared and it acts as an alias or synonym for the variable which was used to initialze it.

There are two ways to pass the variable by reference in C++

1) Traditional pass by reference approach.
someFunction (&a, &b);

void someFunction (int *x, int *y)
{
}


2)
someFunction (a, b);

void someFunction (int &x, int &y)
{
}

In this case no memory is allocated to x & y.
They act as alias for the memory locations to which a & b are referring.
any changes made to the values of x & y will cause values of a & b in the calling function to change respectively.

Both approaches 1) and 2) are called pass by reference. But first approach uses pointers and second approach uses reference variables.

 
Is this answer useful? Yes | No

 Related Questions

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind 
Latest Answer : using the normal goto statement we can move only within the function. it is not possible to go from one function to another function.using setjmp and longjmp you can move from one function to another function. but it is very bad programming. since the ...

An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment 
Latest Answer : lvalue is is a memory location,whose value is not constant i.e it's value is changed when a new value entered into that location.And also it can be say as, it is an expression,where  left side we have an identifier and right side(rvalue) the ...

Latest Answer : a const pointer means the pointer which represents the address of one value. so if you declare a pointer inside the function, it doesn't have scope outside the function. if it is also available to the outside function whenever we declare a pointer as ...
Tags : Pointer

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the 

Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in  
Latest Answer : But isnt like the constant variables will be stored by in ROM (read only memory).Then how can the some process other than the code can change the value of const volatile ...

There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.  The second case 
Latest Answer : Type cast should be used in case of if we want to assign a void pointer to a pointer of some data type.eg:void *ptr;int *c;c=(int *)ptr; ...

A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer 
Latest Answer : we should not cast the big datatype to smaller one. Like from double to float long to integer. TIn these cases there will be chance of loosing the valuable data itself. ...

Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also 
Latest Answer : int num;This statement is declaration and also defination since it also allocates memory for variable num.But when you use following statementextern int num;It is only declaration since you are not allocating memory here. ...

Streams can be classified into two types: text streams and binary streams. Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations 
Latest Answer : Will you please explain how binary mode takes less memory? ...

Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special 


 Sponsored Links

 
Related Articles

jQuery Reference

jQuery Reference Guide by Jonathan Chaffer and Karl Swedberg A Comprehensive Exploration of the Popular JavaScript Library jQuery Reference Guide packtpub com jquery reference guide Open Source book Anatomy of a jQuery Script He s got a brand new start Now he s a happy guy Categ
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Void Pointer and Null Pointer

C Void Pointer and Null Pointer In this C tutorial you will learn about two interesting types of pointers; void pointers and Null Pointer These pointers will be discussed in conjunction with syntax usage and example mosgoogle center Pointer to Void General Syntax void pointer variable; Void is use
 

What is difference between call by value and call by reference in function?

The arguments passed to function can be of two types 1. Values passed 2. Address passed The first type refers to call by value and the second type refers to call by reference. For instance consider program1 main() { int x=50, y=70; interchange(x,y); printf(“x=%d y=%d”,x,
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape