By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

can v do this??

P: n/a
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.

Jun 21 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Jun 20, 10:45 pm, Amar Kumar Dubedy <adub...@yahoo.co.inwrote:
can v write a.foo() in c??
Yes, as can anyone.
if so how can v do it??
Strange question - a text editor would be the obvious way.

Jun 21 '07 #2

P: n/a
On Jun 21, 10:45 am, Amar Kumar Dubedy <adub...@yahoo.co.inwrote:
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.

Yes. "a" can be a struct and "foo" a pointer to function with
no parameters.

#include <stdio.h>
#include <stdlib.h>

typedef struct my_struct_ {
void (*foo) (void);
}my_struct;

void func_foo (void)
{
printf("Yahooooo foo\n");
}

int main (void)
{
my_struct a;

a.foo = func_foo;

a.foo(); /* Here you go ! */

return EXIT_SUCCESS;
}

PS: Writing "We" instead of "v" won't hurt you much :-)

Jun 21 '07 #3

P: n/a
On 6 21 , 1 45 , Amar Kumar Dubedy <adub...@yahoo.co.inwrote:
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.
always, using '->' instead of '.' is a better way ^_^

s->func();
btw, s is a structure pointer.

Jun 21 '07 #4

P: n/a
On Jun 21, 3:11 am, !truth <noddy_zh...@asustek.com.cnwrote:
On 6 21 , 1 45 , Amar Kumar Dubedy <adub...@yahoo.co.inwrote:
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.

always, using '->' instead of '.' is a better way ^_^
What's better about it?

Jun 21 '07 #5

P: n/a
In article <11*********************@j4g2000prf.googlegroups.c om>,
!truth <no*********@asustek.com.cnwrote:
>can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.
>always, using '->' instead of '.' is a better way ^_^
Why?
>s->func();
btw, s is a structure pointer.
But in the example quoted, a is *not* a structure pointer. What would be
the point of getting a pointer to it and then dereferencing it, when you
already have it in hand?

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 21 '07 #6

P: n/a
Amar Kumar Dubedy wrote On 06/21/07 01:45,:
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.
So far, it seems only i can do it. If you find
iv more who can do it, then you'll know that v can
do it.

--
Er*********@sun.com
Jun 21 '07 #7

P: n/a
Amar Kumar Dubedy wrote:
>
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.
Yes. By writing "a.foo()". a.foo should have been properly typed
and initialized earlier.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>
--
Posted via a free Usenet account from http://www.teranews.com

Jun 21 '07 #8

P: n/a
On Jun 21, 3:21 pm, "J. J. Farrell" <j...@bcs.org.ukwrote:
On Jun 21, 3:11 am, !truth <noddy_zh...@asustek.com.cnwrote:
On 6 21 , 1 45 , Amar Kumar Dubedy <adub...@yahoo.co.inwrote:
can v write a.foo() in c?? if so how can v do it?? It is a yahoo
interview question.
always, using '->' instead of '.' is a better way ^_^
Using "->" is only useful when we are playing with pointer to
structure . Say, if we are having a pointer to sturcture p , then to
access a member of the structure through this pointer we will have to
write (*p).member . Since the use of pointer to structure is common, C
has been provided with a simpler way to access structure members i.e.
p->member .

In the above situation, i believe there is no benefit of using -.
>
What's better about it?

Jun 22 '07 #9

P: n/a
Amar Kumar Dubedy <ad*****@yahoo.co.inwrote:
# can v write a.foo() in c?? if so how can v do it?? It is a yahoo
# interview question.

I don't know if Visittors use primitive human programming languages.
If Visittors can fly around in huge spaceship, I suspect they can
do most whatever they want.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Elvis was an artist. But that didn't stop him from joining the service
in time of war. That's why he is the king, and you're a shmuck.
Jun 23 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.