I want to clarify one thing the size of the data type may depend upon your operating system (If you Are using maybe 32 Bit or 64 Bit). Below is a syntax of the sizeof operator in C++. Examsnap is a community of IT certification exam takers committed to sharing their exam knowledge and experience with their peers. Pass Your Next IT Certification Exam with A+ Certification.
Syntax:- sizeof( datatype )
Just replace the datatype in the above syntax with the following datatype and you are done, size operator displays the size of each variable on the screen.
int
float
Syntax:- sizeof( datatype )
Just replace the datatype in the above syntax with the following datatype and you are done, size operator displays the size of each variable on the screen.
int
float
char
double
long double
long long
For Java, the syntax is below you have to only change the datatype but the real data type name.
(datatype.size/8)
(Integer.SIZE/8)
(Long.SIZE/8)
(Character.SIZE/8)
(Float.SIZE/8)
(Double.SIZE/8)
See Also: C++ Program To Display Size Of Different Datatype
See Also: C Program To Display Size Of Different Datatype
double
long double
long long
For Java, the syntax is below you have to only change the datatype but the real data type name.
(datatype.size/8)
(Integer.SIZE/8)
(Long.SIZE/8)
(Character.SIZE/8)
(Float.SIZE/8)
(Double.SIZE/8)
See Also: C++ Program To Display Size Of Different Datatype
Java Program to Find Size of Different Data Types
import java.util.*;
/* how to find size of variable in java */
class SizeofdataTypes {
public static void main(String[] args) {
System.out.println("Size of int: " + (Integer.SIZE / 8) + " bytes.");
System.out.println("Size of long: " + (Long.SIZE / 8) + " bytes.");
System.out.println("Size of char: " + (Character.SIZE / 8) + " bytes.");
System.out.println("Size of float: " + (Float.SIZE / 8) + " bytes.");
System.out.println("Size of double: " + (Double.SIZE / 8) + " bytes.");
}
}
See Also: C Program To Display Size Of Different Datatype
Size of Different Data Types
- Size of int in java: 4 bytes.
- Size of long in java: 8 bytes.
- Size of char in java: 2 bytes.
- Size of Float in java: 4 bytes.
- Size of double in Java: 8 bytes.
Output Size of Data Types
You May Also See
- Java Program To Check Character Is Uppercase, Lowercase Alphabet A Digit Or A Special Symbol
- Java Program To Find Greatest Among Three Numbers
- Java Program For Find The Salary Of An Employee With Employee Grade
- Java Program To Calculate Factorial Of A Given Number
- Java Program For Calculate Percentage Of 5 Subjects
it is very usefull for me thank you
ReplyDeleteThanks
Deletesukanyathota12@gmail.com
ReplyDelete