NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

==================================================================================================================================================
C, C++, Java e Javascript - Tipos de Dados Primitivos
==================================================================================================================================================



1) Descrição

...



2) Tabela comparativa

C,C++,Java,Javascript
-,bool (1 byte),boolean (1 bit),*
char (1 byte / -128 a 127),char (1 byte / -128 a 127),char (2 bytes / ...),*
-,-,byte (1 byte / -128 a 127),*
short(2 bytes / -2^15 a 2^15-1),short (2 bytes / -2^15 a 2^15-1),short (2 bytes / -2^15 a 2^15-1),*
int (4 bytes / -2^31 a 2^31-1),int (4 bytes / -2^31 a 2^31-1),int (4 bytes / -2^31 a 2^31-1),*
long (8 bytes / ...),long (8 bytes / -2^63 a 2^63-1),long (8 bytes / -2^63 a 2^63-1),*
float (4 bytes / ...),float (4 bytes / 1.17549e-38 to 3.40282e+38),float (4 bytes / 1.4E-45 to 3.4028235E38),*
double (8 bytes / ...),double (8 bytes / 2.22507e-308 to 1.79769e+308),double (8 bytes / 4.9E-324 to 1.7976931348623157E308),*


* Javascript é uma linguagem não tipada. O tipo de dados é definido no momento da atribuição do valor para a variável.



3) Exemplos

3.1) Descobrindo o tamanho e a faixa de valores dos tipos primitivos através de linhas de código.


C
---------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <limits.h>
#include <float.h>

int main()
{
printf("char...: %d bytes, %d to %dn", sizeof(char), SCHAR_MIN, SCHAR_MAX);
printf("short..: %d bytes, %d to %dn", sizeof(short), SHRT_MIN, SHRT_MAX);
printf("int....: %d bytes, %d to %dn", sizeof(int), INT_MIN, INT_MAX);
printf("long...: %d bytes, %d to %dn", sizeof(long), LONG_MIN, LONG_MAX);
printf("float..: %d bytes, %d to %dn", sizeof(float), FLT_MIN, FLT_MAX);
printf("double.: %d bytes, %d to %dn", sizeof(double), DBL_MIN, DBL_MAX);

return 0;
}


C++
---------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <limits>

using namespace std;

int main() {
cout << "short..: " << sizeof(short) << " bytes, " << numeric_limits<short>::min() << " to " << numeric_limits<short>::max() << endl;
cout << "int....: " << sizeof(int) << " bytes, " << numeric_limits<int>::min() << " to " << numeric_limits<int>::max() << endl;
cout << "long...: " << sizeof(long) << " bytes, " << numeric_limits<long>::min() << " to " << numeric_limits<long>::max() << endl;
cout << "float..: " << sizeof(float) << " bytes, " << numeric_limits<float>::min() << " to " << numeric_limits<float>::max() << endl;
cout << "double.: " << sizeof(double) << " bytes, " << numeric_limits<double>::min() << " to " << numeric_limits<double>::max() << endl;

return 0;
}


Java
---------------------------------------------------------------------------------------------------------------------------------------------------
public class VariaveisTiposDados
{
public static void main(String[] args)
{
System.out.println("char...: " + (Character.SIZE/8) + " bytes, " + Character.MIN_VALUE + " to " + Character.MAX_VALUE);
System.out.println("byte...: " + (Byte.SIZE/8) + " bytes, " + Byte.MIN_VALUE + " to " + Byte.MAX_VALUE);
System.out.println("short..: " + (Short.SIZE/8) + " bytes, " + Short.MIN_VALUE + " to " + Short.MAX_VALUE);
System.out.println("int....: " + (Integer.SIZE/8) + " bytes, " + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE);
System.out.println("long...: " + (Long.SIZE/8) + " bytes, " + Long.MIN_VALUE + " to " + Long.MAX_VALUE);
System.out.println("float..: " + (Float.SIZE/8) + " bytes, " + Float.MIN_VALUE + " to " + Float.MAX_VALUE);
System.out.println("double.: " + (Double.SIZE/8) + " bytes, " + Double.MIN_VALUE + " to " + Double.MAX_VALUE);
}
}


Javascript
---------------------------------------------------------------------------------------------------------------------------------------------------
<html>
<body>
<script>
document.write("number.: " + Number.MIN_VALUE + " to " + Number.MAX_VALUE + "<br/>");
</script>
</body>
</html>


3.2) Descobrindo o tipo de dados de uma determinada variável através de linhas de código.


C
---------------------------------------------------------------------------------------------------------------------------------------------------
Não é possível


C++
---------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <typeinfo>

using namespace std;

int main()
{
bool varBool;
char varChar;
short varShort;
int varInt;
long varLong;
float varFloat;
double varDouble;

cout << "varBool is of type: " << typeid(varBool).name() << endl;
cout << "varChar is of type: " << typeid(varChar).name() << endl;
cout << "varShort is of type: " << typeid(varShort).name() << endl;
cout << "varInt is of type: " << typeid(varInt).name() << endl;
cout << "varLong is of type: " << typeid(varLong).name() << endl;
cout << "varFloat is of type: " << typeid(varFloat).name() << endl;
cout << "varDouble is of type: " << typeid(varDouble).name() << endl;

return 0;
}


Java
---------------------------------------------------------------------------------------------------------------------------------------------------
Não é possível


Javascript
---------------------------------------------------------------------------------------------------------------------------------------------------
<html>
<body>
<script>
var varBooleana = true;
var varNumInteiro = 1972;
var varNumDecimal = 3.141592;
var varString = "Javascript";

document.write("varBooleana = true" + "<br/>");
document.write("varNumInteiro = 1972" + "<br/>");
document.write("varNumDecimal = 3.141592" + "<br/>");
document.write("varString = Javascript" + "<br/>");

document.write("<br/>");

document.write("Tipo da variavel 'varBooleana' é " + typeof(varBooleana) + "<br/>");
document.write("Tipo da variavel 'varNumInteiro' é " + typeof(varNumInteiro) + "<br/>");
document.write("Tipo da variavel 'varNumDecimal' é " + typeof(varNumDecimal) + "<br/>");
document.write("Tipo da variavel 'varString' é " + typeof(varString) + "<br/>");
</script>
</body>
</html>
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.