Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Your opinion

Reply
Thread Tools

Your opinion

 
 
Martin Ambuhl
Guest
Posts: n/a
 
      09-22-2003
Ravi wrote:

> #define A B
> #define B A
>
> main()
> {
> int A=5;
> float B=6.0;
> printf("\n %d %f",A,B);
> printf(" %d %f",B,A);
> }
>
> Take a look at this program. What is the output?


The same as if the #defines were not there.

> Is it implementation dependent?


The possibility that it might successfully compile and run is
implementation dependent.
>
> Do you think this question aim's at analising a person's C skills?


Only if the correct answer included noticing
1) failure to #include <stdio.h>, to provide the needed prototype for the
variadic function printf.
2) failure to specify the corrent return type of main(), required by C99.
3) failure to return a value from a function which (in C89/C90) promised
implicitly to return an int.
4) mismatched printf specifiers and arguments, attempting stupidly to
print a float with the int specifier %d and to print an int with the
double specifier %f.
5) failure to terminate the last output line with a line-termination
character ('\n'), resulting in implementation-defined behavior.
6) stupid (and pointless) preprocessor tricks.

> (It was asked in a Technical skill paper)


And did the answer include the above points?



--
Martin Ambuhl

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      09-22-2003
Nick Austin wrote:

> On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>
>
>>#define A B
>>#define B A
>>
>>main()
>>{
>> int A=5;
>> float B=6.0;
>> printf("\n %d %f",A,B);

>
>
> Undefined behavior.


Balony. Printing an int with %d and a float with %f is just fine.




--
Martin Ambuhl

 
Reply With Quote
 
 
 
 
Steve Zimmerman
Guest
Posts: n/a
 
      09-22-2003
Ravi wrote:

> #define A B
> #define B A
>
> main()
> {
> int A=5;
> float B=6.0;
> printf("\n %d %f",A,B);
> printf(" %d %f",B,A);
> }
>
> Take a look at this program. What is the output?
> Is it implementation dependent?
>
> Do you think this question aim's at analising a person's C skills?
> (It was asked in a Technical skill paper)
>



Thank you for this post, Ravi.

Output: 5 6.000000 0 0.000000
(There is one space before the 5.)

I don't know if it's implementation dependent.

The code that you cite from the technical skill paper is referred to
as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
is code with an unnecessarily complex and tangled control structure.

http://www.jargon.8hz.com/jargon_34.html#SEC41

_The New Hacker's Dictionary_ is by Eric S. Raymond.


--Steve



 
Reply With Quote
 
Nick Austin
Guest
Posts: n/a
 
      09-22-2003
On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <(E-Mail Removed)> wrote:

>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>>
>>>#define A B
>>>#define B A
>>>
>>>main()
>>>{
>>> int A=5;
>>> float B=6.0;
>>> printf("\n %d %f",A,B);
>>> printf(" %d %f",B,A);
>>>}

>>

>
>Ok, I get the point. But if you were asked this question in a
>technical test with 4 options
>
>a) error during compilation
>b) goes into an infinite loop
>c) 5 6.000000 6 5.000000
>d) 5 6.000000 0 0.000000
>
>What would you choose?


a) is a serious contender, but the examiner probably expects d).

The question is obviously flawed for not including:

e) outputs only a single newline.

Nick.

 
Reply With Quote
 
Ravi
Guest
Posts: n/a
 
      09-22-2003
On Mon, 22 Sep 2003 21:29:32 +0200, Irrwahn Grausewitz
<(E-Mail Removed)> wrote:

>Ravi <(E-Mail Removed)> wrote:
>
>>On Mon, 22 Sep 2003 18:16:45 +0100, Nick Austin
>><(E-Mail Removed)> wrote:
>>
>>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>>>
>>>>#define A B
>>>>#define B A
>>>>
>>>>main()
>>>>{
>>>> int A=5;
>>>> float B=6.0;
>>>> printf("\n %d %f",A,B);
>>>
>>>Undefined behavior.
>>>
>>>> printf(" %d %f",B,A);
>>>
>>>Undefined behavior thrice.
>>>
>>>>}
>>>

>>
>>Ok, I get the point. But if you were asked this question in a
>>technical test with 4 options
>>
>>a) error during compilation
>>b) goes into an infinite loop
>>c) 5 6.000000 6 5.000000
>>d) 5 6.000000 0 0.000000
>>
>>What would you choose?

>
>e) I do not want to work for this company, bye.


But I want to.
Great pay for a fresher like me!

 
Reply With Quote
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      09-22-2003

On Mon, 22 Sep 2003, Steve Zimmerman wrote:
>
> Ravi wrote:
> > #define A B
> > #define B A
> >
> > main()
> > {
> > int A=5;
> > float B=6.0;
> > printf("\n %d %f",A,B);
> > printf(" %d %f",B,A);
> > }
> >
> > Take a look at this program. What is the output?
> > Is it implementation dependent?
> >
> > Do you think this question aim's at analising a person's C skills?
> > (It was asked in a Technical skill paper)

>
>
> Thank you for this post, Ravi.
>
> Output: 5 6.000000 0 0.000000
> (There is one space before the 5.)
>
> I don't know if it's implementation dependent.



STOP STOP STOP STOP STOP STOP STOP STOP STOP!

Thank you.


> The code that you cite from the technical skill paper is referred to
> as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
> is code with an unnecessarily complex and tangled control structure.


Two variables and linear control flow is *not* spaghetti code,
no matter how little you understand of it. "Spaghetti code"
refers to code with complex and/or hard-to-follow control
flow, such as would be difficult to trace on paper.

-Arthur

 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-22-2003
Steve Zimmerman <(E-Mail Removed)> wrote:

>Ravi wrote:
>> #define A B
>> #define B A
>>
>> main()
>> {
>> int A=5;
>> float B=6.0;
>> printf("\n %d %f",A,B);
>> printf(" %d %f",B,A);
>> }
>>
>> Take a look at this program. What is the output?
>> Is it implementation dependent?
>>
>> Do you think this question aim's at analising a person's C skills?
>> (It was asked in a Technical skill paper)
>>

>
>Thank you for this post, Ravi.
>
>Output: 5 6.000000 0 0.000000
>(There is one space before the 5.)


And some small town in southern North Dakota being blown up. =%O

>
>I don't know if it's implementation dependent.


It is. Every single bit of it. Seriously.

>
>The code that you cite from the technical skill paper is referred to
>as "spaghetti code" by _The New Hacker's Dictionary_. Spaghetti code
>is code with an unnecessarily complex and tangled control structure.


Code like this is referred to as being downright idiotic. Period.

Regards

Irrwahn
--
Close your eyes and press escape three times.
 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      09-22-2003
Nick Austin <(E-Mail Removed)> wrote:

>On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <(E-Mail Removed)> wrote:
>
>>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>>>
>>>>#define A B
>>>>#define B A
>>>>
>>>>main()
>>>>{
>>>> int A=5;
>>>> float B=6.0;
>>>> printf("\n %d %f",A,B);
>>>> printf(" %d %f",B,A);
>>>>}
>>>

>>
>>Ok, I get the point. But if you were asked this question in a
>>technical test with 4 options
>>
>>a) error during compilation
>>b) goes into an infinite loop
>>c) 5 6.000000 6 5.000000
>>d) 5 6.000000 0 0.000000
>>
>>What would you choose?

>
>a) is a serious contender, but the examiner probably expects d).
>
>The question is obviously flawed for not including:
>
>e) outputs only a single newline.
>

As well as:

f) most certainly invokes nasal demons when ran on a DeathStation 9000
g) surely you're joking, Mr. employer
h) /What/ the /heck/ is /that/?!?
i) May I have another cup of tea? It's gonna be a loooong answer...
j) Uck!
h) Well, ...

Alright, I stop it now; this list could be continued ad infinitum.

Irrwahn
--
My other computer is a abacus.
 
Reply With Quote
 
Nick Austin
Guest
Posts: n/a
 
      09-22-2003
On Mon, 22 Sep 2003 19:57:30 GMT, Martin Ambuhl
<(E-Mail Removed)> wrote:

>Nick Austin wrote:
>
>> On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>>
>>
>>>#define A B
>>>#define B A
>>>
>>>main()
>>>{
>>> int A=5;
>>> float B=6.0;
>>> printf("\n %d %f",A,B);

>>
>>
>> Undefined behavior.

>
>Balony. Printing an int with %d and a float with %f is just fine.


So an extern int printf(const char *, ...); is not required?

Nick

 
Reply With Quote
 
Bertrand Mollinier Toublet
Guest
Posts: n/a
 
      09-22-2003
Nick Austin wrote:
> On Tue, 23 Sep 2003 00:12:57 +0530, Ravi <(E-Mail Removed)> wrote:
>
>
>>>On Mon, 22 Sep 2003 21:48:21 +0530, Ravi <(E-Mail Removed)> wrote:
>>>
>>>
>>>>#define A B
>>>>#define B A
>>>>
>>>>main()
>>>>{
>>>> int A=5;
>>>> float B=6.0;
>>>> printf("\n %d %f",A,B);
>>>> printf(" %d %f",B,A);
>>>>}
>>>

>>Ok, I get the point. But if you were asked this question in a
>>technical test with 4 options
>>
>>a) error during compilation
>>b) goes into an infinite loop
>>c) 5 6.000000 6 5.000000
>>d) 5 6.000000 0 0.000000
>>
>>What would you choose?

>
>
> a) is a serious contender, but the examiner probably expects d).
>

I don't get it. Why would d) be expected ?

--
Bertrand Mollinier Toublet
Currently looking for employment in the San Francisco Bay Area
http://www.bmt.dnsalias.org/employment

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Your opinion on Kalani Edward MCSD 0 03-10-2005 03:00 AM
Is this dialer watch config OK in your opinion? maxxot2005 Cisco 0 03-03-2005 12:56 PM
What is your opinion of this self study package? MCSD 2 07-06-2004 07:03 AM
Re: Your opinion about stored procedures Ray Dixon [MVP] ASP .Net 1 07-26-2003 08:23 AM
Re: Your opinion about stored procedures mono ASP .Net 1 07-04-2003 07:55 PM



Advertisments