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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:57:12+00:00 2026-06-10T13:57:12+00:00

here is my code. #include <stdio.h> #define MAX(a,b) ((a)>(b)?(a):(b)) #define SZA(a) (sizeof(a)/sizeof(a[0])) int anish=0;

  • 0

here is my code.

#include <stdio.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define SZA(a) (sizeof(a)/sizeof(a[0]))

int anish=0; // global variable showing abrupt behaviour
int a[]={0,1,5,8,9,10,17,17,20,24,30};
int n= SZA(a);

int cache[100];
int road(int len)
{
    anish++;

    if(cache[len]!=-1)
        return cache[len];
    if(len<=0)
        return 0;
    int max=0;
    int i;
    for(i=1;(i<n && len>=i);i++)
    {
        max=MAX(max,a[i]+road(len-i));
    }
    return cache[len]=max;
}

void f()
{
    anish=13;
}

int main()
{
    int i;
    for(i=0;i<=13;i++)
        cache[i]=-1;
    int len=10;
    // f();

    printf("%d %d\n",road(len),anish);
    return 0;
}

In this, road() is a recursive function and I want to calculate the number of times this function is being executed. So, I am doing this via a global variable anish.
But the value of anish is not changing in this road() function, while in function f() value of anish is being modified.

Any reason for this absurd behavior?

  • 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-10T13:57:14+00:00Added an answer on June 10, 2026 at 1:57 pm

    your c code shows an outdated anish variable
    succesive printf’s shows different value

    this has something to do with c’s internals

    it has something to do with this : Parameter evaluation order before a function calling in C

    loki astari said:

    The order that function parameters are evaluated is unspecified
    behavior. (This won’t make your program crash, explode, or order
    pizza… unlike undefined behavior.)

    The only requirement is that all parameters must be fully evaluated
    before the function is called.

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

Sidebar

Related Questions

Here is my code: #include <stdio.h> #include <string.h> #include <windows.h> #include <tchar.h> #define MAX_KEY_LENGTH
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here's my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <wait.h> #include <readline/readline.h> #define
Here is my code: #include<stdio.h> #define MAXLINE 100 /*print the reverse of the input*/
I am going to paste here my code and errors: #include stdio.h #include winsock2.h
Here is my code which checks if the file exists : #include<stdio.h> #include<zlib.h> #include<unistd.h>
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
#include <stdio.h> #include <stdlib.h> #define MAX 20 #define MAX_BASE 8 #define ROW 9 #define

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.