在C ++中编译时间和运行时

时间:2022-07-15 19:50:06

If you created a variable of a primitive type like int, char, float inside a function, did you create that variable at runtime or at compile time?

如果您在函数内创建了一个基本类型的变量,如int,char,float,那么您是在运行时还是在编译时创建该变量?

If you created an object inside a function, did you create that object at runtime or at compile time?

如果在函数内创建了一个对象,是在运行时还是在编译时创建了该对象?

If you create an object by memory allocation through heap, did you create that object at runtime or at compile time?

如果通过堆内存分配创建对象,是在运行时还是在编译时创建了该对象?

What is static memory allocation and dynamic memory allocation?

什么是静态内存分配和动态内存分配?

2 个解决方案

#1


4  

If you created a variable of a primitive type like int, char, float inside a function. Did you create that variable at runtime or at compile time?

如果在函数内创建了一个基本类型的变量,如int,char,float。您是在运行时还是在编译时创建该变量?

You create the variable at run-time, the variable is created when the function is executed, and is destroyed when the function is finished.

您在运行时创建变量,该变量在函数执行时创建,并在函数完成时销毁。

If you created an object inside a function. Did you create that object at runtime or at compile time?

如果在函数内创建了一个对象。您是在运行时还是在编译时创建该对象?

Same as above.

与上面相同。

If you create an object by memory allocation thru heap. Did you create that object at runtime or at compile time?

如果通过内存分配通过堆创建对象。您是在运行时还是在编译时创建该对象?

If you're creating an object on the heap, you're essentially allocating the memory at runtime and get returned a pointer to it. With this pointer, you can read/write to this memory.

如果你在堆上创建一个对象,你实际上是在运行时分配内存并返回一个指向它的指针。使用此指针,您可以读/写此内存。

Static memory, is memory that only be read from at runtime.

静态内存,是仅在运行时读取的内存。

Dynamic memory allocation, refers to allocating objects on the heap and changing them through a pointer to the memory.

动态内存分配,是指在堆上分配对象并通过指向内存的指针进行更改。

#2


0  

No, the const int a=42; //a is created at the compile time and not at run time.

不,const int a = 42; // a是在编译时创建的,而不是在运行时创建的。

#1


4  

If you created a variable of a primitive type like int, char, float inside a function. Did you create that variable at runtime or at compile time?

如果在函数内创建了一个基本类型的变量,如int,char,float。您是在运行时还是在编译时创建该变量?

You create the variable at run-time, the variable is created when the function is executed, and is destroyed when the function is finished.

您在运行时创建变量,该变量在函数执行时创建,并在函数完成时销毁。

If you created an object inside a function. Did you create that object at runtime or at compile time?

如果在函数内创建了一个对象。您是在运行时还是在编译时创建该对象?

Same as above.

与上面相同。

If you create an object by memory allocation thru heap. Did you create that object at runtime or at compile time?

如果通过内存分配通过堆创建对象。您是在运行时还是在编译时创建该对象?

If you're creating an object on the heap, you're essentially allocating the memory at runtime and get returned a pointer to it. With this pointer, you can read/write to this memory.

如果你在堆上创建一个对象,你实际上是在运行时分配内存并返回一个指向它的指针。使用此指针,您可以读/写此内存。

Static memory, is memory that only be read from at runtime.

静态内存,是仅在运行时读取的内存。

Dynamic memory allocation, refers to allocating objects on the heap and changing them through a pointer to the memory.

动态内存分配,是指在堆上分配对象并通过指向内存的指针进行更改。

#2


0  

No, the const int a=42; //a is created at the compile time and not at run time.

不,const int a = 42; // a是在编译时创建的,而不是在运行时创建的。