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

please do this for me

P: n/a
I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?
int func (int (*)(int) , int);
int cube(int n)
{
return (n*n*n);
}
int main()
{
prinf("%d" , func(cube , 4));
}
int func(int (*tmp)(int in) , int n)
{
int res , i;
for(i = 1 ; i <= n ; i++)
res += *(tmp)(i);
return res;
}

Mar 11 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
am*********@gmail.com wrote:
I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?
<snip>

You've not cut and pasted the actual code, (likely since I spotted a
'prinf' instead of printf).

The program as given is broken.

Mar 11 '07 #2

P: n/a

<am*********@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
I got this in a company paper I was
solving online...
Can someone explain me what this code
should do?and whats the error?
int func (int (*)(int) , int);
int cube(int n)
{
return (n*n*n);
}
int main()
{
prinf("%d" , func(cube , 4));
No such thing as prinf.
}
int func(int (*tmp)(int in) , int n)
{
int res , i;
for(i = 1 ; i <= n ; i++)
res += *(tmp)(i);
Probably (*tmp)(i);
return res;
}
And the "error" you are probably asking
about is
res in not initialized.
Mar 11 '07 #3

P: n/a
On Mar 11, 9:51 am, "amey1.ka...@gmail.com" <amey1.ka...@gmail.com>
wrote:
I got this in a company paper I was solving online...
Can someone explain me what this code should do?and whats the error?
My company does that kind of thing for job interviews.

Step 1: Get through some online problems.
Step 2: Go through a phone interview.
Step 3: Go to a real interview.

Step 1 is there so we don't waste your time and our time in Step 2.
Cheating is quite pointless, because if you have to cheat in an online
interview, you won't make it through the phone interview anyway.
(First question in the phone interview: What does the first line in
that program do? )

Mar 11 '07 #4

P: n/a
am*********@gmail.com <am*********@gmail.comwrote:
Can someone explain me what this code should do?and whats the error?
Hm, if you can't be bothered to run a compiler to solve an online
quiz, why would anyone assume you could be bothered to be paid to run
one? There are at least 5 errors in the code you posted.

(The code is not complicated. Make another pass through K&R before
you apply for any other jobs.)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Mar 12 '07 #5

P: n/a
Barry <ba****@nullhighstream.netwrote:
int func(int (*tmp)(int in) , int n)
{
int res , i;
for(i = 1 ; i <= n ; i++)
res += *(tmp)(i);
Probably (*tmp)(i);
Or tmp(i).
And the "error" you are probably asking
about is
res in not initialized.
I'm a little surprised that I did not receive a warning from gcc about
that subtle mistake.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Mar 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.