473,387 Members | 1,834 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,387 software developers and data experts.

question on C language

Interview Question
Visit this site it is really good question on C language.

http://techinterviewquestion.blogspo...-question.html

May 29 '07 #1
5 6318
ru******@gmail.com said:
Interview Question
Visit this site it is really good question on C language.

http://[elided]/c-question.html
Actually, it's a list of questions. None of them are particularly good,
and some of them betray staggering ignorance about the C language.
Example: "Why n++ executes faster than n+1?"

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 29 '07 #2
On May 29, 12:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Actually, it's a list of questions. None of them are particularly good,
and some of them betray staggering ignorance about the C language.
Example: "Why n++ executes faster than n+1?"
That might actually make it a good interview question :-)

The answer could give you a very good reason to hire or to not hire
the interviewee.

May 29 '07 #3
christian.bau said:
On May 29, 12:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>Actually, it's a list of questions. None of them are particularly
good, and some of them betray staggering ignorance about the C
language. Example: "Why n++ executes faster than n+1?"

That might actually make it a good interview question :-)

The answer could give you a very good reason to hire or to not hire
the interviewee.
Ha! :-) And the interviewer's response to the interviewee's answer
could give the interviewee a very good reason to accept or reject a
subsequent offer of a job.

The question is extraordinarily poorly formed. For one thing, the
expressions are not even equivalent! So the matter of relative speeds
is meaningless. For another thing, even if they were equivalent, the
question is based on at least one false premise, and possibly two.

Unpicking that to the satisfaction of a clueful interviewer would take
only a few seconds, of course, but persuading the "potentially bright"
(to borrow Douglas Adams's marvellous phrase) could take substantially
longer. It's probably more cost-effective just to say "so long, and
thanks for the coffee".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 29 '07 #4
>>>>"RH" == Richard Heathfield <rj*@see.sig.invalidwrites:

RHActually, it's a list of questions. None of them are
RHparticularly good, and some of them betray staggering
RHignorance about the C language. Example: "Why n++ executes
RHfaster than n+1?"

This might be a very *good* interview question; it can simultaneously
demonstrate familiarity with C and what the interviewee does when he
disagrees with someone in a position of authority.

It can also be a very good interview question in that, depending on
how it's handled, it can signal to the interviewee that he's being
interviewed by an ignoramus.

Interviews are not solely about ascertaining whether the candidate is
right for the company; they are also about ascertaining whether the
company is right for the candidate. As someone who has been a
candidate in past and who probably will be again in future, I find the
latter to be far more important.

Charlton

--
Charlton Wilbur
cw*****@chromatico.net
May 29 '07 #5
On May 29, 1:28 pm, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
On May 29, 12:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Actually, it's a list of questions. None of them are particularly good,
and some of them betray staggering ignorance about the C language.
Example: "Why n++ executes faster than n+1?"

That might actually make it a good interview question :-)

The answer could give you a very good reason to hire or to not hire
the interviewee.
The question makes no sense without some context. Providing what seems
like a reasonably straightforward context:

#include <stdio.h>

int main(void)
{
int n=0;
n++; /* increment n */
n+1; /* no effect */
printf("%d\n",n);
return 0;
}

I'd suspect that in most modern compilers the n+1 would be optimised
away to nothing (with a diagnostic telling me that it has no effect;
neither of these actions is required by the standard), and so would
execute faster than the n++, so the question is wrong.

The alternative is much worse:

#include <stdio.h>

int main(void)
{
int n=0;
n=n++; /* undefined behaviour */
n=n+1; /* increment n */
printf("%d\n",n);
return 0;
}

Here, it's hard to tell how long the n=n++ will take, especially as I
wouldn't advise running it or even compiling it (after all, anything
could happen). Nevertheless, I came across this code given as an
example of 'code fragments you may want to use' for a compiler for a
language that is not C89, but is the same in the relevant parts of
this discussion. (One of its many sins was that int was unsigned and 8-
bits wide by default, which is one of the reasons I was chafing at
being forced to use it. You could #implemenation_defined_directive it
into a legal 16-bit signed form, at the cost of breaking library
code.)

i=i++;

So by placing this, and some increment code into this non-C-but-close-
enough-for-this-explanation undefined-behaviour-is-bad-but-only-when-
running-the-program-and-at-least-compiling-it-won't-kill-me compiler,
with optimisation off, wrapped in a program to make it legal:

void main(void) /* another of the compiler's sins, but as it was
technically meant to be a
freestanding implementation they may have thought
they could get away with it */
{
int i;
i++;
i=i++;
i=i+1;
i+1;
}

the output was a good guide to the speed of the various commands. I
won't post assembler to comp.lang.c, but instead translate each
statement of the result into C below (with the proviso, of course,
that doing so won't result in a legal C program in almost every case).
The embedded nature of the target meant that the length of time for
each instruction was deterministic, so I'll add it in comments.

/* no startup code was generated, typical for some embedded systems */

/* from i++ */
i++; /* 1 microsecond */
/* from i=i++ */
__W=i; /* 1 microsecond */
i++; /* 1 microsecond */
i=__W; /* 1 microsecond. Of course, as it's UB, this ends up not doing
what you -
or the person who gave it to me as a "useful code fragment"
- might expect. */
/* from i=i+1 */
__W=i; /* 1 microsecond */
__W+=1; /* 1 microsecond */
i=__W; /* 1 microsecond. */
/* from i+1 */
__W=i; /* 1 microsecond */
__W+=1; /* 1 microsecond */

So I suspect on this compiler, the answer is "you didn't turn
optimisation on". The general answer to the question is "It isn't, in
general. In a specific case it may be faster, but it depends on the
compiler, and as the two expressions do different things you shouldn't
have been trying to optimise by hand anyway. Even for a specific
implementation you can't answer the question without knowing the
context in which the expressions appear, and even then just profiling
and finding out yourself is likely to be the most accurate way, but be
careful not to cause undefined behaviour along the way."
--
ais523

May 29 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Anon | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all I am a beginner teaching myself python, and I am enjoying it immensely :) As a language it is great, I real treat to study, I actually...
5
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code...
65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
6
by: Michael | last post by:
Hi, I'm looking for any source-code example, showing the use of midi sequencer and midi messages in C++. Which files have to be included ? I wrote a tool in JAVA which has bad timing problems...
9
by: Milk | last post by:
Hi all, Can anyone help me to do this Question. Coz this is my first time study C++ language and my lecture want me to do this kind of program, i really don't have any ideal pls help me here...
1
by: Milk | last post by:
Hi all, Can anyone help me to do this Question. Coz this is my first time study C++ language and my lecture want me to do this kind of program, i really don't have any ideal, or can send me some...
15
by: John Salerno | last post by:
After my last post, I thought of another question as a result of the following: ------------------------------ Mike Meyer wrote: > John Salerno <johnjsal@NOSPAMgmail.com> writes: > > >>So...
62
by: ROSY | last post by:
hello experts plz answer following questions::: thanks in advance. 1. Out of fgets() and gets() which function is safe to use and why? 2. What is a far pointer? where we use it? 3. What does the...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
26
by: Herbert Kleebauer | last post by:
As part of a simple X demo for Linux I send the byte string in "send8" to the X server. This byte string displays a circle at the x/y position send8.s8x/send8.s8y. In "display()" a 8x8 grid of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.