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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:43:00+00:00 2026-05-28T03:43:00+00:00

This code gives me a seg fault, but when I change the x– to

  • 0

This code gives me a seg fault, but when I change the x-- to --x it prints correctly.

Are not they the same????

int main()
{    
    myFunc(5); 
    return 0;
}

void myFunc (int x) {  
    if (x > 0) {
        myFunc(x--);
        printf("%d, ", x);
    }
    else
        return;
}
  • 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-28T03:43:01+00:00Added an answer on May 28, 2026 at 3:43 am

    No they are not the same.

    The difference between x-- and --x is whether the returned value is before or after the decrement.

    In myFunc(x--), x-- returns the old value. So myFunc() gets called repeatability with the same value -> infinite recursion.

    In myFunc(--x), --x returns the new value. So myFunc() gets called with a decreasing number each time -> no infinite recursion.


    It will be easier to see this if you moved your printf to the start of the function call:

    void myFunc (int x) {  
        printf("%d, ", x);
    
        if (x > 0) {
            myFunc(x--);
    
        }
        else
            return;
    }
    

    Output: (when called with 10)

    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this code, for vector size, n >=32767, it gives segmentation fault, but upto
Why this code gives error: #include<iostream> #include<vector> using namespace std; int main() { char
This very simple code gives me tons of errors: #include <iostream> #include <string> int
The following code in javascript gives me the error this.callback is not a function
Okay, this code gives me exactly what I want but it seems that it
This line of code gives the following warning: short[] sh = null; for (int
This code gives me an empty result. I expect it to print out the
Can anyone explain why this code gives the error: error C2039: 'RT' : is
This code in JS gives me a popup saying i think null is a
This piece of code gives a syntax error at the colon of elif process.loop(i,

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.