944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2731
  • C++ RSS
Jun 24th, 2005
0

Few problems in char and pointers.

Expand Post »
I am using borland C++ compiler ver-3.0 for running C & in that range of char type is -127 to 127.
Q1 In C, characters have ASCII codes in range 0-255. How can we print characters having ASCII code from 128-255.
printf("%c",(unsigned)129); //it will still print the char having ASCII -127
Q2 ASCII char range is 0-255,then where do the characters having -127 to 0 ASCII code come from.
Q3 Where r the local & global static variables stored.
Q4 I read that const variables r stored in rom. How cum bcoz as far as i know rom can be programmed only by hardware means.
Q5
C++ Syntax (Toggle Plain Text)
  1. int a=9999;
  2. float *p=(float *)&a;
  3. printf("%f",*p); //output is 0.000000 why?
Q6
C++ Syntax (Toggle Plain Text)
  1. printf("%d%d",10ul,10); //output is 100 why?
Q7
C++ Syntax (Toggle Plain Text)
  1. float f=10.67;
  2. int *p=(int *)&f;
  3. printf("%d",*p); //output is -18350 why?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akshayabc is offline Offline
15 posts
since Jun 2005
Jun 24th, 2005
0

Re: Few problems in char and pointers.

Quote originally posted by akshayabc ...
Q1 In C, characters have ASCII codes in range 0-255. How can we print characters having ASCII code from 128-255.
printf("%c",(unsigned)129); //it will still print the char having ASCII -127
ASCII is a 7-bit code, ranging from 0 - 127. Extended ASCII may be different here or there. The character you may see may be the extended ASCII character whose value is 129.
Quote originally posted by akshayabc ...
Q2 ASCII char range is 0-255,then where do the characters having -127 to 0 ASCII code come from.
See above.
Quote originally posted by akshayabc ...
Q3 Where r the local & global static variables stored.
Why do you ask? If it's homework, take a stab at it first.
Quote originally posted by akshayabc ...
Q4 I read that const variables r stored in rom. How cum bcoz as far as i know rom can be programmed only by hardware means.
The keyword const really means read-only. Whether or not a const variable is placed in ROM depends on the platform.
Quote originally posted by akshayabc ...
Q5
C++ Syntax (Toggle Plain Text)
  1. int a=9999;
  2. float *p=(float *)&a;
  3. printf("%f",*p); //output is 0.000000 why?
Behavior is undefined because you are lying to printf.
Quote originally posted by akshayabc ...
Q6
C++ Syntax (Toggle Plain Text)
  1. printf("%d%d",10ul,10); //output is 100 why?
See above. (My output is 1010).
Quote originally posted by akshayabc ...
Q7
C++ Syntax (Toggle Plain Text)
  1. float f=10.67;
  2. int *p=(int *)&f;
  3. printf("%d",*p); //output is -18350 why?
See above. (My output is 1093318738).
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 25th, 2005
0

Re: Few problems in char and pointers.

Thanks a lot Dave for answering my questions. I was searching for these answers for last 1 year. Also tell me where are global & local staic variables stored. I am not able to find the answer for that and believe me its not a homework.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akshayabc is offline Offline
15 posts
since Jun 2005
Jun 25th, 2005
0

Re: Few problems in char and pointers.

Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ char array parsing-Help
Next Thread in C++ Forum Timeline: Please some one help me in this code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC