asit said:
THANK YOU.....finally i got the answer
You got an answer, but not to the question you were asking.
I took your original question to mean: take the posted program, and
replace the comment with some statement *making no other changes* so
that the final program prints "19". KM's "solution" changes the
previous line from
char p='19';
to
char p=\x19';
If you can make any change you like to the entire program, the
solution is trivial. A more sensible change would have been to
change the declaration to
char *p = "19";
(If you're going to be participating here, you should know that Kenny
McCormack is a troll; you'll be better off if you ignore everything he
writes. Don't take my word for it; take a look at his posting
history. I expect he'll post some stupid personal insult in response
to this.)
Some of us have been hesitant to give you a solution because the
problem looks like homework; we generally try not to do people's
homework for them, because the whole point is to learn something.
But since a valid answer has already been posted, I'll bite. The
original code was:
#include <stdio.h>
int main()
{
char p='19';
//write a statement to print 19 on screen
return 0;
}
Here's my solution:
#include <stdio.h>
int main()
{
char p='19';
printf("19\n");
return 0;
}
I'm assuming that the "char p='19';" declaration was deliberately
misleading; the original problem statement didn't say that the output
had to be derived from the value of p.
And in fact there's no portable way to do so. A character constant
with more than one character between the single-quote characters has
an implementation-defined value. Unless you either read the
documentation for your compiler or write a program to display the
value, you have no way of knowing what value will actually be stored
in p.
It rarely makes any sense to use such character constants in the first
place.