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

  • SEARCH
  • Home
  • 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 8755819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:55:49+00:00 2026-06-13T13:55:49+00:00

I think that my code works. However, it outputs 01111E5, or 17B879DD, or something

  • 0

I think that my code works. However, it outputs 01111E5, or 17B879DD, or something like that.

Can someone please tell me why.

I am aware that I set the limit of P instead of 10,001. My code is like that because I start with 3, skipping the prime number 2.

#include <iostream>
bool prime (int i)
{
bool result = true;
int isitprime = i;
for(int j = 2; j < isitprime; j++)              ///prime number tester
{
    if(isitprime%j == 0) result = false;
}   
return result;
}


int main (void)
{
using namespace std;
int PrimeNumbers = 1;
int x = 0;
for (int i = 3 ; PrimeNumbers <=10000; i++)
{
    if(prime(i))
    {
        int prime = i;
        PrimeNumbers +=1;
    }
}   
cout<<prime<<endl;
system ("pause");
return 0;
}
  • 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-06-13T13:55:50+00:00Added an answer on June 13, 2026 at 1:55 pm

    The output isn’t strange at all.

    cout<<prime<<endl;
    

    You’re printing the function pointer of prime here.

    You were probably intending to print the variable you create here:

     int prime = i;
    

    But this is in the loop scope. In fact, if you compile with warnings enabled, your compiler should tell you that this variable is never used. Also, it’s bad practice to give variables in C or C++ the same name as functions (or any other variable in a higher level scope).

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

Sidebar

Related Questions

I'm think something like Facebook apps here. User generated pieces of code that people
Funny thing is that if i delete the comment for alert(data[i].id) the code works.
I have a cool snippet of code that works well, except one thing. The
I think that looking at others' code is a good way to learn. I'm
The code below shows me (I think) that the for each loop is about
Here is a simple code that shows what I think is a bug when
i know that there isn't code inside my question, but i think this is
here's my code that works thanks to Jim b: SELECT IIf([Lab Occurrence Form].[1 0
The objective here is to have a pointer that works like a 2D matrix.
One thing that really bothers me about Google Code is that fact that it

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.