> Can I have the below code in C? (I don't want to use a pointer.)
If you're going to cripple yourself before you start, no you can't.
I assume you want a real re-usable answer and not some silly side trick like
- disguise your pointer as an array of 1 element
- global variables
- pre-processor macro tricks.
Firstly, "doesn't work" is a useless problem description. Tell us clearly, precisely and completely what behaviour you're seeing, and how it differs from the behaviour you expect.
Something I can see right away is that you're using a reference as an argument to doit(). References are a C++ feature, not a C feature, so you'll need to change that.
The obvious way to fix it would be to use a pointer argument instead. Is there any good reason why you don't want to use them?
That link offers using a c++ compiler on your 'extended C' to use c++ & syntax and also shows that the & syntax is not available in C without the extensions. Which is just more words and pictures over what was already said in here.
I assume you mean "I want to use c++ references" not "I don't want to use any pointers".
C is going to be nearly unusable without pointers, probably lots of them, if you plan to write anything of substance.
If you are going to write C with a few C++ extensions anyway, that was a thing in the late 80s... its not a bad pseudolanguage as far as it goes. All you are really doing is writing C++ and using the C relic code that is pulled in by nature of C++ being built from C originally. Its not really a useful thing to do today; the languages have split too far apart. I learned C++ using that style, and all it has accomplished is bad habits that I still struggle to break. Its bad professionally: no shop is going to tolerate such code. Its good because you can do a lot with a little for small home projects if you are just coding as a hobby or something -- you get performance in a smaller, easier to learn package. Though, if you don't get pointers, it may not be easier to learn ... its critical path for C or hybrid C.