Your opinion

R

Ravi

#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)
 
B

Ben Pfaff

Ravi said:
#define A B
#define B A

Pointless and stupid and effectively a no-op besides.

You should declare main() as explicitly returning `int'. This is
required in C99. You should also write `void' within the
parentheses to give it a prototype, though it is not required.
{
int A=5;
float B=6.0;
printf("\n %d %f",A,B);
printf(" %d %f",B,A);

You should return a value from main().
}

Take a look at this program. What is the output?
Is it implementation dependent?

It is undefined for at least two reasons: first, trying to print
out an `int' using %f; second, for failing to write a final
new-line character to stdout.
Do you think this question aim's at analising a person's C skills?
(It was asked in a Technical skill paper)

I think it aims at testing something, but it has little to do
with C skills, especially considering the stupid macro
definitions. It tests knowledge of C trivia, not knowledge of C
usage.
 
R

Ravi

You should declare main() as explicitly returning `int'. This is
required in C99. You should also write `void' within the
parentheses to give it a prototype, though it is not required.

What's worse it had void main() originally and also a clrscr()
somewhere in between.

And the funniest part:
"What is the output on compiling the program:"
When they actually meant running the program.

LOL
And they think they are testing someones technical skill.

One more redicilous question:
#define scanf "%s is a string"
void main()
{
printf(scanf,scanf);
}

What's the output?
I think the output of this is not certain as well.

(Don't blame me as THEY did not feel like including any header file
and felt like using void main()
)
 
R

Ravi

Undefined behavior.


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?
 
I

Irrwahn Grausewitz

Ravi said:
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.

;-)

Irrwahn
 
M

Mark Gordon

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?

Depends on whether I wanted the job. They probably expected d, but I
would definitely be inclined to point out that the question was absurd
and that the code invoked UB. However I don't think I would want a job
where they asked such questions.
 
M

Martin Ambuhl

Ravi said:
#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?
 
S

Steve Zimmerman

Ravi said:
> #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
 
N

Nick Austin

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.
 
A

Arthur J. O'Dwyer

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
 
I

Irrwahn Grausewitz

Steve Zimmerman said:
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
 
I

Irrwahn Grausewitz

Nick Austin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top