Few problems in char and pointers.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 15
Reputation: akshayabc is an unknown quantity at this point 
Solved Threads: 0
akshayabc akshayabc is offline Offline
Newbie Poster

Few problems in char and pointers.

 
0
  #1
Jun 24th, 2005
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
  1. int a=9999;
  2. float *p=(float *)&a;
  3. printf("%f",*p); //output is 0.000000 why?
Q6
  1. printf("%d%d",10ul,10); //output is 100 why?
Q7
  1. float f=10.67;
  2. int *p=(int *)&f;
  3. printf("%d",*p); //output is -18350 why?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Few problems in char and pointers.

 
0
  #2
Jun 24th, 2005
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.
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.
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.
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.
Originally Posted by akshayabc
Q5
  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.
Originally Posted by akshayabc
Q6
  1. printf("%d%d",10ul,10); //output is 100 why?
See above. (My output is 1010).
Originally Posted by akshayabc
Q7
  1. float f=10.67;
  2. int *p=(int *)&f;
  3. printf("%d",*p); //output is -18350 why?
See above. (My output is 1093318738).
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 15
Reputation: akshayabc is an unknown quantity at this point 
Solved Threads: 0
akshayabc akshayabc is offline Offline
Newbie Poster

Re: Few problems in char and pointers.

 
0
  #3
Jun 25th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Few problems in char and pointers.

 
0
  #4
Jun 25th, 2005
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC