Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:21:58+00:00 2026-06-07T22:21:58+00:00

What is the difference in the following code:- int a; int *p; p=&a; function(p);

  • 0

What is the difference in the following code:-

 int a;
 int *p;
 p=&a;
 function(p);

and

 int a;
 function(&a);

I was reading a book where sometimes they have used the first code and sometimes the other. Its not a good book though (by a local author).

Will both codes work the same way or is there any difference?

Also is there any difference in terms of efficiency and does it matter that much?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:22:00+00:00Added an answer on June 7, 2026 at 10:22 pm

    As far as I know compiler implements references as pointers. So there should be no difference in performance. But references are more strict and can protect you from making mistakes. For example you can’t rebind references or can’t perform arithmetic with them

    Also some people prefere to pass pointers to the function that modify object. For example

    void changeVal(int *p)
    {
        *p = 10;
    }
    

    They say it’s more readable when you see:

       changeVal(&var)
    

    than

    changeVal(var);
    

    EDIT

    You can think of reference as another name of the object it refers to. So all the changes made to reference are applied to the object. Here is an example:

    void foo_copy(int a) //pass by copy
    {
        a = 10; //changes copy
    }
    
    void foo(int &a) //bass by reference
    { 
         a = 10; //changes passed value
    }
    
    void foo(int *a) //pass an adress of a
    {
        (*a) = 10; //change a value pointed by a
        a = nullptr; //change a (the pointer). value is not affected
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please check following code tell me what the difference between Convert.ToInt32() and int() ,
What is the difference between the following 2 examples of code: (function(){ var myFunc
I have a problem with the following code #include <stdio.h> int main() /* Tidsberäkning
Let's say I have following code: int f() { int foo = 0; int
I have the following code: Code 1 class Student { int no; char grade[M+1];
I have the following code: public function ajax() { // Contains results $data =
What is the difference between the following code? CREATE TYPE f1_MemberType AS OBJECT (
i am using the following code(based on this http://goo.gl/5HhSx ) to calculate the difference
Using LINQ on collections, what is the difference between the following lines of code?
What is the difference between the following two snippets of code: using (Object o

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.