Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 586967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:44+00:00 2026-05-13T15:09:44+00:00

I was provided this simple C++ [I think] program to investigate the maximum size

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:09:44+00:00Added an answer on May 13, 2026 at 3:09 pm

    You are compiling C++ code with gcc in a file with .c extension?

    // Use new C++ header files instead of their .h version.
    #include <climits>
    #include <iostream>
    
    // cout and endl are declared in the std namespace.
    using namespace std;
    
    int 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;
    
      return 0;
    }
    

    and use g++ to compile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this is a simple one, but can anyone provide some simple c# code
I know that this is subjective and all, but still, can you provide some
I'd like to know what you think about this part of our program is
Alright, this one (3a; sample problem with provided answer) has got me scratching my
If this is possible, please provide a sample query or two so I can
Hoping someone can provide an answer with this, although it's not 100% programming related.
Can someone provide some light on how to do this? I can do this
I need to create what I think should be a simple GUI. I have
I am writing a program in c++ that accepts a filename as an argument
Everyone uses source-code control to manage versions (right?) and this provides some level of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.