Hi,
I was provided this simple C++ [I think] program to investigate the maximum size of int that can be stored:
#include <limits.h>
#include <iostream>
void main ( int argc , char * argv[])
{
cout << "INT_MAX " << INT_MAX << endl ;
cout << "INT_MAX +1 = " << INT_MAX + 1 << endl ;
cout << "INT_MAX -1 = " << INT_MAX - 1 << endl ;
cout << "INT_MAX / INT_MAX " << INT_MAX /INT_MAX << endl ;
cout << "(INT_MAX +1) / INT_MAX " << (INT_MAX +1) /INT_MAX << endl;
cout << "(INT_MAX -1) / INT_MAX " << (INT_MAX -1) /INT_MAX <<endl;
cout << "INT_MAX / (INT_MAX +1) " << INT_MAX /(INT_MAX+1) <<endl;
cout << "INT_MAX / (INT_MAX -1) " << INT_MAX /(INT_MAX -1) <<endl;
}
I'm attempting to compile with:
gcc -o int_max int_max.cpp
But I get the following error:
int_max.cpp:4: error: '::main' must return 'int'
int_max.cpp: In function 'int main(int, char**)':
int_max.cpp:8: error: 'cout' was not declared in this scope
int_max.cpp:8: error: 'endl' was not declared in this scope
int_max.cpp:9: warning: integer overflow in expression
int_max.cpp:13: warning: integer overflow in expression
int_max.cpp:15: warning: integer overflow in expression
I tried adding a return 0 at the end of main but that didn't help. Any idea what I've done wrong?
P.S It's possible this is actually a C snippet but I seem to remember the lecturer saying it was C++.
Cheers