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 6378921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:04:15+00:00 2026-05-25T02:04:15+00:00

I have faced the following interview question. Consider this function declaration: void quiz(int i)

  • 0

I have faced the following interview question.

Consider this function declaration:

void quiz(int i)
{
    if (i > 1)
    {
        quiz(i / 2);
        quiz(i / 2);
    }
    writeOutput("*");
}

How many asterisks are printed by the function call quiz(5)?

My answer was:

Languages (Javascript, PHP, etc.) with integer division result type is
float – seven asterisks. Function quiz get called:

  1. With i=5 – once, asterisk printed.
  2. With i=2.5 – twice, asterisks printed.
  3. With i=1.25 – four times, asterisks printed.
  4. With i=0.625 – eight times, no asterisks printed

Languages (C/C++, C#, Java, etc.) which division result type name is
integer – three asterisks. Function quiz get called:

  1. With i=5 – once, asterisk printed.
  2. With i=2 – twice, asterisks printed.
  3. With i=1 – four times, asterisks not printed.

Question syntax is like C/C++, Java, so the answer would be three

The interview was a closed book exam – during the interview I was unable to run this code and check it. The interviewer told me that my answer is not absolutely correct (or at least, they didn’t expect it to be like this). Hovewer, I’ve ran this code (with PHP, Javascript and C#) at home and the result was as I described.

So, are there some caveats I’m missing or my answer was just more detailed than they were expecting?

  • 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-25T02:04:17+00:00Added an answer on May 25, 2026 at 2:04 am

    If you change the code to this:

    void quiz(int i)
    {
        if (i > 1)
        {
            quiz(i / 2);
            quiz(i / 2);
        }
        printf("* for %d\n", i);
    }
    

    You’ll see that the result for quiz(5) is:

    * for 1
    * for 1
    * for 2
    * for 1
    * for 1
    * for 2
    * for 5
    

    So, you got the correct number of calls per i, you just didn’t notice that the writeOutput is outside the if, not inside it.

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

Sidebar

Related Questions

I faced an interview. where I was asked the following question Write a function
Say I get the following question Console.WriteLine(Which teams have faced eachother? - use Red
I seem to have faced this problem many times and I wanted to ask
I have faced this problem quite often during the last couple of months, during
I have faced aweird problem with the following code, the code below suppose to
I've faced the following problem. I'm developing a form for the site and this
Currently im faced with the following problem: I have a script that searches through
I'm faced with the following problem in rails. I have a form to edit/create
I am faced with the following issue. Consider the following class: //Will be similar
I have found this site very useful for all my previously faced problems, However

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.