Olá... estou começando a estudar a apostila online, e surgiu algumas dúvidas quanto aos tipos de variáveis:
No link "Modificadores do tipo inteiro - short, long, signed e unsigned "
fiz o exercício pra ver o tamanho das variáveis e o algoritmo ficou assim:
#include <stdio.h>
int main()
{
printf("int : %d bytes\n", sizeof( int ) );
printf("short int: %d bytes\n", sizeof( short ) );
printf("long int: %d bytes\n", sizeof( long ) );
printf("signed int : %d bytes\n", sizeof( signed int ) );
printf("short signed int: %d bytes\n", sizeof( signed short ) );
printf("long signed int: %d bytes\n", sizeof( signed long ) );
printf("unsigned int : %d bytes\n", sizeof( unsigned int ) );
printf("short unsigned int: %d bytes\n", sizeof( unsigned short ) );
printf("long unsigned int: %d bytes\n", sizeof( unsigned long ) );
}
Mas o resultado não foi como eu esperava, pois a mesma memória foi reserva pra signed e unsigned,
veja o print na tela:
int : 4 bytes
short int: 2 bytes
long int: 4 bytes
signed int : 4 bytes
short signed int: 2 bytes
long signed int: 4 bytes
unsigned int : 4 bytes
short unsigned int: 2 bytes
long unsigned int: 4 bytes
Process returned 27 (0x1B) execution time : 0.008 s
Press any key to continue.
unsigned não deveria reservar menos memória? Sabe me dizer o que houve?
Aguardo a resposta!!!
No link "Modificadores do tipo inteiro - short, long, signed e unsigned "
fiz o exercício pra ver o tamanho das variáveis e o algoritmo ficou assim:
#include <stdio.h>
int main()
{
printf("int : %d bytes\n", sizeof( int ) );
printf("short int: %d bytes\n", sizeof( short ) );
printf("long int: %d bytes\n", sizeof( long ) );
printf("signed int : %d bytes\n", sizeof( signed int ) );
printf("short signed int: %d bytes\n", sizeof( signed short ) );
printf("long signed int: %d bytes\n", sizeof( signed long ) );
printf("unsigned int : %d bytes\n", sizeof( unsigned int ) );
printf("short unsigned int: %d bytes\n", sizeof( unsigned short ) );
printf("long unsigned int: %d bytes\n", sizeof( unsigned long ) );
}
Mas o resultado não foi como eu esperava, pois a mesma memória foi reserva pra signed e unsigned,
veja o print na tela:
int : 4 bytes
short int: 2 bytes
long int: 4 bytes
signed int : 4 bytes
short signed int: 2 bytes
long signed int: 4 bytes
unsigned int : 4 bytes
short unsigned int: 2 bytes
long unsigned int: 4 bytes
Process returned 27 (0x1B) execution time : 0.008 s
Press any key to continue.
unsigned não deveria reservar menos memória? Sabe me dizer o que houve?
Aguardo a resposta!!!