The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Sizeof data types
Discuss Sizeof data types in the C Programming forum on Dev Shed. Sizeof data types C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 6th, 2012, 10:54 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 30
Time spent in forums: 11 h 3 m 34 sec
Reputation Power: 1
|
|
|
Sizeof data types
I am getting output for below code as 8 4 4 in gcc version 4.5.2. Can anyone explain why I am getting this output ?
Code:
#include<stdio.h>
int main()
{
printf("%d\t",sizeof(6.5));
printf("%d\t",sizeof(90000));
printf("%d",sizeof('A'));
return 0;
}
|

November 6th, 2012, 11:48 PM
|
 |
Lost in code
|
|
|
|
|
Because on your system, a floating point number is 8 bytes, an integer is 4 bytes, and a character is 4 bytes.
|

November 7th, 2012, 12:24 AM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 30
Time spent in forums: 11 h 3 m 34 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by E-Oreo Because on your system, a floating point number is 8 bytes, an integer is 4 bytes, and a character is 4 bytes. |
How can integer and char can take same byte size ?
I guess I found the answer. In sizeof('A'), 'A' is replaced by 65 and sizeof(65) which is integer and that's how it shows 4. Not very sure though.
|

November 7th, 2012, 01:28 AM
|
 |
Contributed User
|
|
|
|
|
> printf("%d",sizeof('A'));
In C, character constants are integers, but in C++, character constants are chars.
If you compiled this as a C++ program, you would most likely see 8 4 1 as the output.
|

November 7th, 2012, 04:31 AM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 30
Time spent in forums: 11 h 3 m 34 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by salem > printf("%d",sizeof('A'));
In C, character constants are integers, but in C++, character constants are chars.
If you compiled this as a C++ program, you would most likely see 8 4 1 as the output. |
Thank you.
|

November 7th, 2012, 01:57 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
|
size of a double
sizeof an int
sizeof a character constant
In C a character constant in an int not a char.
|

November 8th, 2012, 03:27 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 35 m
Reputation Power: 0
|
|
|
Hi,
you can get value of int but not get value of character.
Thanks!
|

November 8th, 2012, 02:37 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by miteshaegis you can get value of int but not get value of character. |
What does that mean? A character constant is an int, and a char is an integer type so also has a "value".
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|