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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:51:26+00:00 2026-05-17T18:51:26+00:00

Lets say I have the function void do_work (foo?); The ? represents a 0

  • 0

Lets say I have the function

 void do_work (foo?);

The ? represents a 0 or a 1 which will be the value of variable

 int bar = 0;

There are also the variables

 int foo0 = 0;
 int foo1 = 0;

I am trying to inject the value of one variable into the name of another variable so that the function gets the full name of either variable depending on preceding logic.

How can I do this?

(In this situation, i’m not worried about good or bad practice.)

  • 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-17T18:51:26+00:00Added an answer on May 17, 2026 at 6:51 pm

    C doesn’t work in the way that perhaps you are thinking. You cannot dynamically refer to the name of a variable at runtime like you may be used to in other languages.

    That said, the name of the function’s arguments is irrelevant.

    void do_work(int arg)
    {
    } 
    

    You don’t have to match up the name of arg with foo0 or foo1. Now you can pass either variable into the function:

    int foo0, foo1;
    
    if (some_condition)
      do_work(foo0);
    else
      do_work(foo1);
    

    Now the function do_work will be working on a copy of the variable passed. So if you change the variable’s value inside the function, it will still remain the same outside the function. You can change that by returning a new value:

    int do_work(int arg)
    {
      return arg + 1;
    }
    
    foo0 = do_work(foo0);
    

    Lastly, it sounds like you want to use an array:

    int foo[2]; // create two ints: foo[0] and foo[1]
    
    do_work(foo[0]);
    
    int i = 1;
    do_work(foo[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say you have simple template function (not class member for the sake of
I am working on a legacy framework. Lets say 'A' is the base-class and
I have a logging function that takes the calling object as a parameter. I
I have this very awkward question... void changeString(String str){ str = Hello world: }
I have a very old, very very large, fully working, C program which plays
I have the following interface: internal interface IRelativeTo<T> where T : IObject { T
Is it possible to establish a set of templated function pointers, without the hassle
Some standard C libraries that I want to access with Cython have a ton
...or, how do I filter a sequence of classes by the interfaces they implement?
in the past we encountered various memory-leaks in our software. We found out that

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.