473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

can v do this??

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

Jun 21 '07 #1
9 1362
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company...
5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
2
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form...
2
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") ||...
0
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.