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 947805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:08:21+00:00 2026-05-15T23:08:21+00:00

In C++, what is the difference between: void func(MyType&); // declaration //… MyType *

  • 0

In C++, what is the difference between:

 void func(MyType&); // declaration

 //...
 MyType * ptr;

 func(*ptr); // compiler doesnt give error

 func(ptr); // compiler gives error i thought & represents memory address so 
            // this statement should correct as ptr is only a pointer
            // or address of some real var.
  • 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-05-15T23:08:21+00:00Added an answer on May 15, 2026 at 11:08 pm

    The unary prefix operator &, when applied to an object, yields the address of the object: &obj.
    The type modifier &, when applied to a variable about to be declared, will modify the variable’s type to be a reference type: int&.

    The same applies to *: When applied as a unary prefix operator to a pointer, it will dereference the pointer, yielding the object referred to: *ptr.
    When used as a type modifier to a variable about to be declared, * will modify the type to be a pointer: int*.

    In a similar way, the type modifier [] applied to a variable that’s being declared will modify the variable’s type to an array, while the binary infix operator [] applied to an object of array type will access one of the array’s sub-objects.


    It’s not helpful that type modifiers apply to the variable that is declared, not to the type they are declared with. For example, this

    int *p, **pp, i, a[10], &r = i; 
    

    defines an int pointer, a pointer to a pointer to an int, a vanilla int, an array of 10 int, and an int reference. (The latter is immediately initialized, because you cannot have an uninitialized reference.) Note that the type modifiers syntactically belong to the declared variable whose type they are modifying, not to the declared variable’s type. Nevertheless, type modifiers (* and &) modify the type of the variable.
    In the following case, however, with p, i, and a presumed to be variables that have already been declared

    *pp = &i;
    a[0] = i;
    

    * and & are unary prefix operators dereferencing pp and yielding the address of i, while [] yields the first int object in the array a.

    The fact that C and C++ don’t care about the whitespaces around type modifiers and that this led to different camps when it comes to place them doesn’t really make things easier.
    Some people place the type modifiers close to the type. They argue that it modifies the type and so it should go there:

    int* ptr;
    

    The disadvantage is that this becomes confusing when declaring several objects. This

    int* a, b;
    

    defines a to be a pointer to int, but b to be an int. Which is why some people prefer to write

    int *ptr;
    int *a, *b;
    

    I suggest to simply never declare multiple objects in the same statement. IMO that makes code easier to read. Also, it leaves you free to pick either convention.


    To complicate things even further, besides the type modifiers and the unary prefix operators & and *, there are also the binary infix operators & and *, meaning “bitwise AND” and “multiplication”. And to add insult to injury, in C++ you can overload both the unary prefix and the binary infix variants of these operators (and the binary infix []) for user-defined types and be completely free as to their semantics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can try using select() just as a timer. I… May 16, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer You just need to override onCreateDialog in an Activity. //In… May 16, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer Make use of the PHP's built-in function shuffle to do… May 16, 2026 at 5:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

What is the difference between void func(const Class *myClass) and void func(Class *const myClass)
Whats the difference between a Null pointer & a Void pointer ?
I was thinking about the difference between Expression<Func<>> and Func<> , and wondered if
What would be the difference between these two seemingly similar declarations? When would you
What is the difference between normal reflection and the reflection that can be done
What is the difference between a variable declared as dynamic and a variable declared
Possible Duplicates: C++ Virtual/Pure Virtual Explained What's the difference between virtual function instantiations in
Consider the following code: public class Vehicle { public void StartEngine() { // Code
When I read litb answer to this question , I learned that passing an
I have a very simple queue implementation that wraps a fixed array. It contains

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.