D
Daniel Antonson
What is the effect of the following code?
char Ch;
Ch = '7';
printf("%d\n", Ch);
char Ch;
Ch = '7';
printf("%d\n", Ch);
The choices available are:
a. It will cause an error
The choices available are:
a. It will cause an error
b. It will print out the computer's internal code for the character '7'
c. It will print out the character '7'
d. It will print out the character whose internal code is 7
Daniel said:What is the effect of the following code?
char Ch;
Ch = '7';
printf("%d\n", Ch);
What made u think that i didn,t tried thatWalter said::Answer will be 'b'
What answer will be 'b'? You didn't quote any establishing context.
:It will print out the computer's internal code for the character '7'
Obviously you didn't try it.
As it will print the ASCII value of '7' which is 55sandeep said:Answer will be 'b'
It will print out the computer's internal code for the character '7'
As it will print the ASCII value of '7' which is 55
Michel said:idk, seems obvious to me that it prints the ascii value of '7'. is it a
question to tell newbies in C from others?
What is the effect of the following code?
char Ch;
Ch = '7';
printf("%d\n", Ch);
>
> idk, seems obvious to me that it prints the ascii value of '7'. is it a
> question to tell newbies in C from others?
sandeep said:Walter said:What made u think that i didn,t tried that
I tried and i got "55" as the internal value of '7'.
Which is also the ASCII value for "7".
Now i got it correct and you might be having some problem with your
compiler or you missed something.
Any compiler that compiles the program *as given* is broken.
Perhaps you put some kind of wrapper around the code, but the
question was not "What would the code do if it were repaired",
the question was what the code would do -- and the answer to
that is that the code *given* is not a valid compilable C program.
If you were able to compile and execute the code *exactly as given*,
with full ANSI/ISO compliance mode turned on, then please let us
know what compiler you were using -- so that we will know to avoid it.
We were asked to interpret some code and say what it did, not to
indicate what *some other code* that sort of resembles the original
might do.
If you feel that for the sake of such questions that it is acceptable
to toss in header inclusions and function wrappers and such, then
you should be answering for all other possible manipulations of
the code -- such as inserting Ch = Ch / (Ch - '7'); in the middle.
If you are going to presume the presence of additional statements,
then why not presume the presence of additional code that will trigger
nasal demons or World War VI or a rise in the price of pork bellies?
In my opinion, when asked what code does, one should answer the
question about the code presented, not about what code might be there.
Mark Babli said:"If you were able to compile and execute the code *exactly as given*,
with full ANSI/ISO compliance mode turned on, then please let us
know what compiler you were using -- so that we will know to avoid it.
."
Answer:
DevC++ 4.9
Project ==> Options==> ANSI (Check) ==> OK
#include <stdio.h>
int main(int argc, char *argv[])
{
char Ch;
Ch = Ch / (Ch - '7');
printf("%d\n", Ch);
return 0;
}
and the result was:
0
Borland C++ Builder 6 rejected it (Big-time).
Walter said:sandeep said:Obviously the given code would not compile i agree but what i done is:Walter said:Any compiler that compiles the program *as given* is broken.
Perhaps you put some kind of wrapper around the code, but the
question was not "What would the code do if it were repaired",
the question was what the code would do -- and the answer to
that is that the code *given* is not a valid compilable C program.
If you were able to compile and execute the code *exactly as given*,
with full ANSI/ISO compliance mode turned on, then please let us
know what compiler you were using -- so that we will know to avoid it.
#include<stdio.h>
void main()
{
char ch;
ch = '7';
printf("%d\n",ch);
return 0;
}
Walter said:sandeep said:Obviously the given code would not compile on any comipler because ofWalter said:Any compiler that compiles the program *as given* is broken.
Perhaps you put some kind of wrapper around the code, but the
question was not "What would the code do if it were repaired",
the question was what the code would do -- and the answer to
that is that the code *given* is not a valid compilable C program.
If you were able to compile and execute the code *exactly as given*,
with full ANSI/ISO compliance mode turned on, then please let us
know what compiler you were using -- so that we will know to avoid it.
missing header and all & we are assumed to add that(Mere common sense).
and the code which i compiled was:
#include<stdio.h>
main()
{
char ch;
ch = '7';
printf("%d\n",ch);
return 0;
}
Now is it okay for you.
Now compile it and it will print "55".
^^^^sandeep said:Obviously the given code would not compile i agree but what i done is:
#include<stdio.h>
void main()
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.