Some Quick Questions

1. Why range of float constants is much more than integer constants ?

2. Can i write an entire C program in a single line including all preprocessors. If yes, how ?

3. As per the definition, a character variable can hold only one character constant at time. But suppose if i declare a character variable with bogus input and print it's value as shown below,

1
2
char ch = 'winner';  
printf("\nch = %c",ch);


I get the output "r", the last character (Code::Blocks). And these warnings,
1
2
warning: character constant too long for its type
warning: overflow in implicit constant conversion



So, it looks like last character is assigned to character variable. I understand the first warning. But what about the second, that led to the storage of 'r' in character variable "ch" ?

Also refer me to resources/papers if applicable.

Regards
~Legend_Xeon
Last edited on
closed account (9wX36Up4)
Reply 2: Yes

Reply 3:char can use for only a single charecter but except for this char ch[6]={'w','i','n','n','e','r'};

U should use "string" for 'Winner'
Reply 2: Thanks. Glad to know it's possible. But what if we were to include preprocessor too?

Reply 3: You are not getting me bro. I am asking about the effect of bogus input on output

Also i want a reply to my first question. :)
1 ) Because "int" can't hold decimal values
1) It has to do with how floating point values are stored. They include data bits for an exponent, allowing you to store very large but less precise numbers.

2) I actually do not think so. Preprocessor commands are terminated with newlines.

3) I would think that shouldn't even compile. Single quotes are for character literals only, not string literals. Anything it would do in that case that it does somehow run would be implementation defined.
1. float:
4bytes = 32bits
Single precision:
sign: 1bit
exponent: 8bit --> as Zhuge mentioned
significand: 23bit
total: 32bits

http://en.wikipedia.org/wiki/Floating_point
ah. Thanks very much all for clarifying the doubts. :)
Topic archived. No new replies allowed.