Marcelo Cohen, FACIN - PUCRS
/*
This is a comment made of
many lines
*/
int main()
{
int i;
for(i=0;i<20;++i)
printf("%d\n",i); // Write number on screen
puts("Done");
}
int i = 5;
cout << "The value of i is " << i << endl;
int i;
cin >> i;
int main()
{
int x = 0;
...
for (int c=0; c<20; c++)
cout << c << endl;
...
int v = x + c;
...
}
#define MAX 100
const int MAX = 100;
void calc(const int x)
{
x++; // Compilation error: x has been declared as "const"
...
}
typedef struct
{
int x,y;
} Point;
struct Point
{
int x,y;
};
void func(float x)
{
cout << "Float parameter: " << x << endl;
...
}
void func(int x)
{
cout << "Int parameter: " << x << endl;
...
}
void func(char* x)
{
cout << "Pointer to char parameter: " << x << endl;
}
void calc(int a, int b, int c=5)
{
...
}
In this case, the function may be called passing 2 or 3 parameters:calc(5, 6);
// Or:
calc(5, 6, 2);
// Allocating a 100-element int array
int* v;
v = malloc(sizeof(int)*100));
...
// Freeing memory
free(v);
// Allocating a 100-element int array
int *v;
v = new int[100];
...
// Freeing memory
delete [] v;
|
|
|
|