954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Few problems in char and pointers.

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

int a=9999;
   float *p=(float *)&a;
   printf("%f",*p);      //output is 0.000000 why?

Q6

printf("%d%d",10ul,10); //output is 100 why?

Q7

float f=10.67;
    int *p=(int *)&f;
    printf("%d",*p);       //output is -18350 why?
akshayabc
Newbie Poster
15 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 
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.Q2 ASCII char range is 0-255,then where do the characters having -127 to 0 ASCII code come from.See above.Q3 Where r the local & global static variables stored.Why do you ask? If it's homework, take a stab at it first.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 keywordconst really means read-only. Whether or not a const variable is placed in ROM depends on the platform.
Q5

int a=9999;
   float *p=(float *)&a;
   printf("%f",*p);      //output is 0.000000 why?

Behavior is undefined because you are lying toprintf.
Q6

printf("%d%d",10ul,10); //output is 100 why?

See above. (My output is 1010).Q7

float f=10.67;
    int *p=(int *)&f;
    printf("%d",*p);       //output is -18350 why?

See above. (My output is 1093318738).

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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.

akshayabc
Newbie Poster
15 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You