Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

If char is 8 bits and int is 16- predict the values of -7 - 3 and size.docx

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 2 Anuncio

If char is 8 bits and int is 16- predict the values of -7 - 3 and size.docx

Descargar para leer sin conexión

If char is 8 bits and int is 16, predict the
values of -7 % 3 and sizeof(-5 % 3). Why?
A. two possibilities: -1 and 2 or 2 and 2
B. A general prediction cannot be made
for all implementations.
C. -1 and 2 or -1 and 4 depending upon
the data type of sizeof
D. two possibilities: -1 and 2 or 1 and 2
E. three possibilities: -1 and 2 or 2 and 2
or -2.3 and 2
Solution
ANSWER - Option C
If char is 8 bits and int is 16, then the values of -7 % 3 (considering -7%3 as by default signed integer expression ) and sizeof(-5 % 3) would be -1 and 2 or -1 and 4 as the size of an int is really compiler dependent. Previously, when processors were 16 bit, an int was 2 bytes. Nowadays, it\'s most often 4 bytes on a 32 bits system. C99 added new types where you can explicitly mention for a certain sized integer, for example int16_t or int32_t. Prior to that, there was no universal way to get an integer of a specific size.
e.g.
#include <iostream>
using namespace std;
int main() {
int a=-7%3;
cout<<a<<endl;
int b=-5 % 3;
cout<<sizeof(b);
return 0;
}
.

If char is 8 bits and int is 16, predict the
values of -7 % 3 and sizeof(-5 % 3). Why?
A. two possibilities: -1 and 2 or 2 and 2
B. A general prediction cannot be made
for all implementations.
C. -1 and 2 or -1 and 4 depending upon
the data type of sizeof
D. two possibilities: -1 and 2 or 1 and 2
E. three possibilities: -1 and 2 or 2 and 2
or -2.3 and 2
Solution
ANSWER - Option C
If char is 8 bits and int is 16, then the values of -7 % 3 (considering -7%3 as by default signed integer expression ) and sizeof(-5 % 3) would be -1 and 2 or -1 and 4 as the size of an int is really compiler dependent. Previously, when processors were 16 bit, an int was 2 bytes. Nowadays, it\'s most often 4 bytes on a 32 bits system. C99 added new types where you can explicitly mention for a certain sized integer, for example int16_t or int32_t. Prior to that, there was no universal way to get an integer of a specific size.
e.g.
#include <iostream>
using namespace std;
int main() {
int a=-7%3;
cout<<a<<endl;
int b=-5 % 3;
cout<<sizeof(b);
return 0;
}
.

Anuncio
Anuncio

Más Contenido Relacionado

Similares a If char is 8 bits and int is 16- predict the values of -7 - 3 and size.docx (20)

Más de edwardk6 (20)

Anuncio

Más reciente (20)

If char is 8 bits and int is 16- predict the values of -7 - 3 and size.docx

  1. 1. If char is 8 bits and int is 16, predict the values of -7 % 3 and sizeof(-5 % 3). Why? A. two possibilities: -1 and 2 or 2 and 2 B. A general prediction cannot be made for all implementations. C. -1 and 2 or -1 and 4 depending upon the data type of sizeof D. two possibilities: -1 and 2 or 1 and 2 E. three possibilities: -1 and 2 or 2 and 2 or -2.3 and 2 Solution ANSWER - Option C If char is 8 bits and int is 16, then the values of -7 % 3 (considering -7%3 as by default signed integer expression ) and sizeof(-5 % 3) would be -1 and 2 or -1 and 4 as the size of an int is really compiler dependent. Previously, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32 bits system. C99 added new types where you can explicitly mention for a certain sized integer, for example int16_t or int32_t. Prior to that, there was no universal way to get an integer of a specific size. e.g. #include <iostream> using namespace std; int main() { int a=-7%3; cout<<a<<endl; int b=-5 % 3; cout<<sizeof(b); return 0; }

×