function - c++ program for address and variables -


the output code :

9

and i'm not sure change in function add1 , &n mean , when assign i &n

#include <iostream> using namespace std;  int add1(int &n){     n++;     return n; }  int main(){     int m = 0;      (int = 0; < 5; i++){         m += add1(i);            }     cout << m ;     cout << "\n\n";      return 0; } 

when & used in parameter list, cause parameter passed reference function.

what means n in function add1, point same space in memory i in main function. changes n reflected in i, act different names same thing.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -