#include <utility>
#include <iostream>
#include <math.h>
std::pair<double, double> cart2pol(double real, double imag)
{
std::pair<double, double> result;
result = std::make_pair(sqrt(pow(real, 2)+pow(imag, 2)), atan(imag/real));
return result;
}
int main()
{
std::cout << "Mag: " << cart2pol(1, 1).first << std::endl << "Phase: " << cart2pol(1, 1).second << std::endl;
}
#include <iostream>
// test the funny warning from compiler
double * assign ()
{
// double out[2]; // works but causes the famous error
double* out = (double *)malloc(2 * sizeof(double));
out[0] = 0;
out[1] = 1;
return out;
}
int main ()
{
double *in = 0;
in = assign();
double first = in[0];
double second = in[1];
std::cout << first << " and " << second << std::endl;
free(in);
return 0;
}
Klasse variable = Klasse (parameter);
Klasse variable = parameter;
Klasse variable (parameter);
Klasse *variable = new Klasse (parameter);
delete variable;
Klasse * field = new Klasse [128];
delete [] field;
MyClass **MyVar = new MyClass*[5];
for( ulong i=0; i
for( ulong i=0; i
int x,y;
int **a = new int*[x];
for (int i = 0; i
another example
double **pp;
int n = 3,m=4;
// Allocation
pp = new double* [n];
for(register int i=0; i=0; i--)delete [] pp[i];
delete [] pp;
another example
// allocation
double** pp = new double* [n];
pp[0] = new double [n*m];
for (int i = 1; i
// declaration
int *p; // pointer to an int value
int i; // a variable with integer value
// usage
p = &i; // p will contain the address of i
i = *p; // i will contain the value pointed to by p
const Object* obj; // can't change data
Object const *obj; // same as const Object* obj;
Object* const obj; // can't change pointer
const Object* const obj; // can't change data or pointer
// Reads a file and throws out an n-tuple
TNtuple * create_ntuple_from_file (const char* filename){
ifstream in;
in.open(filename);
Float_t x,y,df;
Int_t nlines = 0;
TNtuple *ntuple = new TNtuple("ntuple","x, y and Frequency","x,y,df");
while (1) {
in >> x >> y >> df;
if (!in.good()) break; ntuple->Fill(x,y,df); nlines++;
}
cout ReadFile(filename, "freq:ampldb");
cout Draw("ampl:freq>>h1","","cont4");
h1->GetXaxis()->SetTitle("Frequency");
h1->GetYaxis()->SetTitle("Amplitude");
c1->Update();
return 0;
}