answersLogoWhite

0

in java, char consumes two bytes because it uses unicode instead of ascii. and int takes 4 bytes because 32-bit no will be taken

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How many bytes required for int float double char boolean?

Int: 4 bytes Float: 4 double: 8 char: 1 boolean: 1


How do you calculate ascii value in java?

char a = 'A'; System.out.println((int)a);


How do you convert a char to an int in java?

Assuming - char mychar ; and int myint have been properly declared, myint = (int) mychar; // converts This is a feature of Java= to change types, put the type you want to convert into in parenthes before the variable that stores the converted value. ^Will convert your char into an int, but it will be the ascii value. For example, mychar = 3; myint = (int) mychar; //returns 51 To make an accurate one that will not return an error, you can use a try-catch statement Example char mychar = '3'; try { int myint = (int) mychar; }catch(NumberFormatException e) { //Do whatever you want with it! }


What are the only types in Java that are not classes?

The non-class Java data types are primitives: * byte * short * int * long * float * double * boolean * char


Integers need how many bits to stored in C plus plus?

It depends on the type of integer (such as long, short, int and char) and the specific implementation of C++. The only guarantee is that a char must occupy one byte (sizeof(char)==1). An int is typically 32-bits (4 bytes), but only sizeof(int) can tell you for sure.


Why does a character constant require two bytes of memory space in c?

It doesn't. Try this #include <stdio.h> #include <wchar.h> int main (void) { printf ("sizeof (char)=%d, sizeof (wchar_t)=%d\n", (int)sizeof (char), (int)sizeof (wchar_t)); return 0; }


Eight basic data types used in java?

char, boolean, byte, short, int, long, double, or float


How many bytes does an Boolean take in a c program?

There is no boolean in C, we usually use int/short/char to store logical values.


Why do you define variables before clear screen function in c?

Variables need only be defined before they are actually used, so there is no need to define them before calling any functions that don't actually use them, including clear screen functions. However, by moving all the declarations to the top of the function, and sorting them in descending order of size, you minimise memory consumption by eliminating any unnecessary padding for alignment purposes. For example, suppose your function uses the following variables in this order: char ch1; int i1; char ch2; int i2; char ch3; int i3; char ch4; int i4; Assuming an int is 4 bytes, this will consume up to 32 bytes in total, because the int variables should ideally be aligned upon 32-bit boundaries. Thus each char variable wastes 3 bytes. By sorting them from largest to smallest, you reduce the consumption to just 17 bytes: int i1; int i2; int i3; int i4; char ch1; char ch2; char ch3; char ch4; Saving just 15 bytes for one function may seem insignificant, but when applied to every function those savings can be quite substantial. The more memory you save, the smaller your code will be, and therefore the quicker it will execute. The only problem with doing this is that variables are then scoped to the function, rather than to the statement bodies that actually use them. However, once a function has been fully debugged, it makes sense to optimise its memory consumption and then test one more time to ensure no bugs have crept in.


What is earlier declaration for main?

pick one: int main (void); int main (int argc, char **argv); int main (int argc, char **argv, char **envp);


Bzero function in socket programming?

bzero: writes the specified number of null bytes to the specified destination. bzero(char *dest, int nbytes);


What is the function in java to find the size of given variable?

Dependion on the variable there are several methods to do it, this can only be applied to primitive types and arrays, for an array its the "name_of_array.length", for the arraylist this change just a little, it would be like "name_of_array_list.size()", for an int, double, float, long, byte, it would be like "name_of_variable.LENGTH" this is a public variable so you dont need a get, an finally for the String there is a method "name_of_string.length()" this would return the size of this String