60 likes | 170 Views
Examples. float x = 10.7; float& rx = x; cout <<x<< endl ; //output: 10.7 cout <<&x<< endl ; //address of x in memory cout << rx << endl ; // output: 10.7 cout <<& rx << endl ; //address of in memory = &x -- rx ; // equivalent to --x;. int i ,*j; i =5;
E N D
float x = 10.7; float& rx = x; cout<<x<< endl; //output: 10.7 cout<<&x<<endl; //address of x in memory cout<<rx<< endl; // output: 10.7 cout<<&rx<< endl; //address of in memory = &x --rx; // equivalent to --x;
inti,*j; i=5; cout<<“------------------------------" <<endl; cout<<i<<endl; //output: 5 cout<<&i<<endl; //output: i address in memory j=&i; cout<<j<<endl; //output: i address in memory cout<<“---------------------------------" <<endl;
#include <iostream> using namespace std; int count(int x); int main() { int x=3; cout<<"value of count(x)= "; cout<<count(x)<<endl; return 0; } int count (int x) { if (x==0) return 0; else { cout<<x; return count(x-1); } }
#include <iostream> using namespace std; int count(int x); int main() { int x=3; cout<<"value of count(x)= "; cout<<count(x)<<endl; return 0; } int count (int x) { int y; if (x==0) return 0; else { y = count(x-1); cout<<x; return y; } }
#include <iostream> #include <string> using namespace std; void call_by_v(string); //call by value void call_by_rr(string &); //call by reference using reference void call_by_rp(string *); //call by reference using pointer int main() { string s = "Welcome"; call_by_v(s); cout<<s<<endl; call_by_rr(s); cout<<s<<endl; call_by_rp(&s); cout<<s<<endl; return 0; } void call_by_v(string a) { a=" s will not changed"; } void call_by_rr(string & a) { a="s will change using reference"; } void call_by_rp(string *a) { *a="s will change using pointers"; }