how to use a variable without reference

A

Ant Franck

hi friends,

is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable?

void main()
{
int a=10;
fun();
}

fun()
{
printf("%d", a);
}

condition
1. don't use pointer concept
2.don't declare as global variable
3.don't send as arguments

IS IT POSSIBLE?

please help me
 
?

=?iso-2022-kr?q?=1B=24=29CHarald_van_D=0E=29=26=0F

hi friends,

is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable? [...]
condition
1. don't use pointer concept
2.don't declare as global variable
3.don't send as arguments

IS IT POSSIBLE?

Why would you want to?

Anyway, it depends on what at least "as", "global", and "variable" mean.
With some legitimate interpretations, there are certainly ways around the
pointless restrictions you (or your instructor) gave.
 
D

Default User

Ant said:
hi friends,

is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable?

void main()
{
int a=10;
fun();
}

fun()
{
printf("%d", a);
}

condition
1. don't use pointer concept
2.don't declare as global variable
3.don't send as arguments

Why?



Brian
 
C

Christopher Benson-Manica

[comp.lang.c] Ant Franck said:
is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable?

Search the archives of this group for the answer, which is "do your
own homework"...
void main()

....and get a professor with a clue...
printf("%d", a);

....and terminate your output with a newline.
 
W

Walter Roberson

is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable?

In some implementations, Yes.

If you want to know *How* to do it, at the very least you'll have
to google up my posting on the topic about 2 months ago, when
someone presented the same question in almost exactly the same words.
 
W

Walter Roberson

ok so how do you do it? can't find anything on google.

Just look up your previous thread, when you posted using the
name "Anto Frank", using your email address (e-mail address removed)
 
A

Ant Franck

ok thanks. i stopped reading that when i got lots of unhelpful and
unfreindly replies... do you have the url?
 
K

Kenneth Brody

Ant said:
hi friends,

is it possible to call a variable from the main function to a sub
fuction with out sending as a argument, pointer and can't declare as
global variable?

No.

What teacher and/or school keeps giving students this question? It
gets posted in nearly identical form every few weeks.
void main()
{
int a=10;
fun();
}

fun()
{
printf("%d", a);
}

condition
1. don't use pointer concept
2.don't declare as global variable
3.don't send as arguments

IS IT POSSIBLE?

The answer is that it's not possible unless you invoke undefined
behavior whose behavior you happen to know because you know some
intimate details about the particular compiler, including being
tied to a specific version of that compiler and a particular set
of compilation options.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Kenneth Brody

(Top-posting corrected.]

Ant said:
ok thanks. i stopped reading that when i got lots of unhelpful and
unfreindly replies...

Why do you expect to get anything more useful than the "it cannot
be done" answer you got the last time?
do you have the url?

And when you can't even be bothered to look up your own messages,
especially when you were posting from Google the last time (and
even this one was routed through Google before it got to me),
don't expect people to give you very much help.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top