1. What are the output results of the following programs?
#include <stdio.h>
Main () {
int b=3;
int arr[]={6,7,8,9,10};
int *ptr=arr;
* (ptr++) +=123;
printf ("%d,%d\n", *ptr,* (++ptr));
}
Answer:
8,8
In C, printf calculates the parameters from right to left.
2. What are the output results of the following programs?
#include <iostream>
using namespace Std;
int main () {
float a = 1.0f;
cout << (int) a << Endl;
cout << &a << Endl;
cout << (int&) a << Endl;
cout << "Boolalpha" << ((int) A = = (int&) a) << Endl;
cout << Endl;
cout << Endl;
float B = 0.0;
cout << (int) b << Endl;
cout << &b << Endl;
cout << (int&) b << Endl;
cout << "Boolalpha" << ((int) b = = (int&) b) << Endl;
GetChar ();
return 0;
}
Answer:
(int) A is to resolve the value of an in-memory cell from another type to an int type and create a temporary object.(int &) A is to tell C + + memory to be an int type and return a reference object.
(int&) A = = Static_cast<int&> (a) (int) &a = = reinterpret_cast<int> (&a);(int&) A is not converted, Directly get a in memory unit value (int) A A in memory value converted to int type float type in memory is stored in the form of the sign bit exponent mantissa by the 754 standard: order code with the increment code (the complement of the inverse symbol), the mantissa adopts the original code so 1.0f in memory in the form of 0011 1111 1000 0000 0000 0000 0000 0000 So the output is the storage form of 0x3f8000000 in memory 0000 0000 0000 0000 0000 0000 0000 0000 (int&) a casts a into shaping reference types (int) &a to cast the address of a to an integer type
(int&) A is equivalent to
* (int*) &a
* (int*) (&a)
* ((int*) &a)
The float type is interpreted as an int type.
3. What is the output of the following function?
#include <iostream>using namespace Std;int main () {unsigned int a = 0XFFFFFFF7; unsigned char i = (unsigned char) A; char* b = (char*) &a; printf ("%08x,%08x", I, *b); GetChar ();}
Answer:
Char *b= (char *) &a
in the X86 series of machines. The storage of data is "small-end storage", the meaning of small-end storage. For a data that spans multiple bytes, its lows are stored in low-address cells, with highAddress Unit. For example, an int type of data ox12345678, if stored in the 0x00000000,0x00000001,0x00000002,0x00000003 four memory units, then put in ox00000000 low ox78. And ox00000003 in the high 0x12, and so on.
char* b = (char*) &a; What the hell is this saying? In fact, it's simple. &a can think of it as a pointer to unsigned int type data, right. (char *) &a the &a to a char * type pointer, and this time a truncation occurred. After truncation, pointer b simply points to the OXF7 data, and because pointer b is char * type. belongs to a signed number. So the signed number 0xf7 output FFFFFFF7 in printf () (This process actually occurs when the parameter type is promoted by default argumentpromotions).%x represents the output of the 16 binary integer type.
C + + program Ape Classic Face question (2)