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?

Recommended Answers

All 3 Replies

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 keyword const 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 to printf.

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).

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.