C++
C++
C++
Namespace
Scope in C++ can be named. Scope in C++ can contain
declaration statements or definition statements.
cout
cout is an object/variable of type ostream class in C++.
Main purpose of cout is to print the contents onto the standard
output device.
Namespace
#include <iostream>
using namespace std;
namespace nm1
{
int a;
}
namespace nm2
{
int b;
}
int main() {
nm1::a = 20; nm2::b = 30;
cout<<nm1::a<<endl<<nm2::b<<endl;
2
Reference variables
In C++ an alias for an existing variable can be created, termed
as reference variables.
Ex: int a = 10;
int &r = a;
cout<<r<<a; output: 10 10
Call by reference
#include <iostream>
using namespace std;
3
void accept(int &, int &);
void display(int, int );
void swap(int &, int &);
int main() {
int i,j;
accept(i,j);
cout<<"Before swapping ";
display(i,j);
swap(i,j);
cout<<"After swapping ";
display(i,j);
return 0; }
4
Whenever dynamic memory is acquired, using a new operator
address of the memory will be returned. In order to store the
address a pointer of the specific type will be necessary.