hi,

i have started learning c for 1 week and i am using VS 2005.
from tutorials i learned that size of char is 1 byte
i am using 32bit system
but i tried this program:

# include<stdio.h>
void main()
{
char a,b;
a=0xfffffffffffffffe; //now a is holding 8bytes thst is sizeof a double datatype
b=0x1;
b=a+0x1;
printf("size of  varaible A:%d\n",sizeof(a));
printf(value in a is:%x\n value in b is:%x);
return;
}

output was
size of varaible A:1
value in a is:fffffffe

value in b is:ffffffff

my question are:
1)when i added one more f in "a" variable a=0xfffffffffffffffef then when i compiled it showed me the error constant too big(bcoz its more than 32 bit) then why it didnot show earlier this erro message when i assigned value(0xfffffffffffffffe) to char a which greater than it can hold ie 0xff(1 byte size maximum valu that char can hold)

2)
even if "A" has holded the whole 8 bytes in it then why did take only last 4 bytes for calculation?

Or VS 2005 itself expands the datasize from char to float or double ?

Please help

Technically it's not a constraint violation so the compiler isn't required to produce a diagnostic message. At best you'd get a warning for a persnickety compiler. For example, Comeau gives me a warning under default settings, but Pelles C doesn't except for the highest warning level. Visual C++ 2010 doesn't even give the warning with /Wall.

Welcome to C, where the compiler won't stop you from doing the majority of bad things. You actually have to know the language and program carefully. ;)

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.