some queries for pointers and imputs

This is a discussion on some queries for pointers and imputs within the C++ Programming forums, part of the General Programming Boards category; Code: (1) void exam(int &x){ } //call the function exam(x); what is the meaning of this? shouldn't be say Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    65

    some queries for pointers and imputs

    Code:
    (1)
     void exam(int &x){
    }
    
    //call the function
    exam(x);
    what is the meaning of this?
    shouldn't be say
    Code:
     void exam(int *x){
    }
    
    //call the function
    exam(&x);
    (2)
    if we call a function like this
    Code:
    (2)
    void exam2(istream cin){
    }
    exam2(cin);
    //call it
    [/code]
    cin use the iostream library but when we declare the function we use istream which
    iostream inherit from it , what would be the different if we was declaring the function with iostream library
    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    "int &" is a type, called "reference to int". It is not the same as "pointer to int".

    For the second, there is an issue related to the first: you don't want to create a new istream; you should instead pass a reference to an istream (many istreams, like cin, cannot be copied). iostream inherits from both istream and ostream; if the function was expecting an iostream&, it would not be able to accept an istream& object -- which means you wouldn't be able to pass (say) cin into it, since cin is an istream object not an iostream object. (However, if you keep the istream& parameter, you can pass in any child object, like an iostream& object.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some queries on arrays
    By jackson6612 in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2011, 04:33 AM
  2. two small queries
    By jackson6612 in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2011, 04:30 AM
  3. special queries for databases
    By Leite33 in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2006, 04:23 AM
  4. text file queries
    By ozzy34 in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2004, 10:42 AM
  5. Hash File Queries
    By 1999grandamse in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2002, 01:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21