March 20, 2020

The memory space is divided into different areas, where functions are used

void* malloc(unsigned int size);

Applicable memory ()

Correct answer: C Your answer: C (correct)

程序区
静态存储区
动态存储区
ROM区

The stack is automatically allocated by the system. The heap requires the programmer to apply for it. The function malloc is used in C to allocate space, free is used, C ++ is allocated with new, and delete is used to release.

Of course, children's shoes that love java must be more concerned about the division of java's memory space (although powerful java allows the programmer to not need to consider too many memory details when programming)

Java divides the memory space into five parts;
stack, heap, method area, local method area, and register.
1. Stack memory: Storage is local variables . As long as the variables defined in the method are local variables.
The variable is released once its life cycle is over.
2. The heap memory is an entity (object) (created by the new keyword).
Each entity has a first address value.
The variables in the heap memory have default initialization values . Different types are different,
int-0, double-0.0 boolean-false char-'\ u0000'
When the entity is not in use, it will be processed by the garbage collection mechanism.

 

If there are the following definitions and statements:

1

int a[10]={1,2,3,4,5,6,7,8,9,10},*p=a;

Then the expression that cannot represent an array element is

Correct answer: B Your answer: B (correct)

*p
a[10]
*a
a[p-a]

Answer: B

Resolution:

A: Equivalent to a [0]

B: I think the subscript of the array starts from 0, so 10 is out of bounds.

C: equivalent to a [0]

D: p and a point to the same array, you can do addition and subtraction (if p and a do not point to the same array, you will get an error), the resulting value is an integer. This question is 0. So D is also equivalent to a [0].

What is wrong in the following description of the union?

Correct answer: A Your answer: C (wrong)

联合变量定义时不可初始化
联合的成员是共址的
联合的成员在某一个时刻只有当前的是有效的
联合变量占有的内存空间是该联合变量中占有最大内存空间的成员在内存对齐时所需的存储空间

 

Variables of union type can be initialized at the time of definition, defined as the following union type

1

2

3

4

5

6

union Test

{

    int a;

    float b;

};

Test test = {1};

The definition of the test variable can be initialized. The type of the initial value must be the type of the first member in the union.

Enter when the following program is running: 123456789↙

Then the result of the program is ()?

1

2

3

4

5

6

7

8

9

#include <stdio.h>

main()

{

       int  x, y;

       scanf("%2d%*4s%2d",

&x, &y);

       printf("%d",

y-x);

}

 

% 2d reads the first two characters first% * 4s skips 4 characters% 2d reads two characters so x is 12 y is 78 yx = 66

 

 

 

Assuming that A is an abstract class, the following statement () is correct.

Correct answer: D Your answer: B (wrong)

int fun(A);
A Obj;
A fun(int);
A *p;

 

An abstract class cannot be initialized, cannot be used as a return value, cannot be used as a parameter , and can be used as a pointer variable because it has not been initialized at this time

 

 

When using the setw () operator to format the data, the () file should be included.

Correct answer: D Your answer: C (wrong)

fstream.h
stdlib.h
iostream.h
iomanip.h

Regarding formatted input and output , the standard library defines a set of manipulators ( manip ulator) to modify the format state of the stream. (Refer to "C ++ Primer" P666 "Formatting input and output")

These manipulators (such as setprecision and other manipulators that accept parameters) are defined in the header file iomanip . ("C ++ Primer" P669)

( The name of the header file can be remembered according to the English writing manipulator in the IO library : iomanip.h )

Published 225 original articles · Like 140 · Visit 250,000+

Guess you like

Origin blog.csdn.net/jankin6/article/details/104988511
Recommended