- 类里边 类成员变量只能声明不能定义,由构造函数对其定义
- 如果类中含有常量(const属性不可改值)或引用型(定义时就得给值)的成员变量,必须通过初始化表对其初始化
- 在类的声明中给定构造函数的缺省值,类的实现里边不能给定缺省值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
var x int | |
threads := runtime.GOMAXPROCS(0) | |
for i := 0; i < threads; i++ { | |
go func() { | |
for { x++ } | |
}() | |
} | |
time.Sleep(time.Second) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
var x, y int | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
x := []int{1, 2, 3} | |
for _, v := range x { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"fmt" | |
"io" | |
"log" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c++ 缺省参数注意事项: | |
1.如果一个参数带有缺省值,那么它后边的所有参数必须都带有缺省值 | |
2.如果一个函数声明和定义分开,那么缺省参数只能放在声明中。因为编译器编译时看的是函数声明 | |
3.缺省参数避免和重载发生歧义 | |
c++ 中 ++i 和 i++的实现: | |
int operator++(); // 前++ | |
int operator++(int); // 后++ | |
用到哑元 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void foo(void) { | |
int tmp; | |
printf("%d\n", tmp); | |
tmp = 999; | |
} | |
int main() { | |
foo(); // 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 判断栈的增长方向 | |
* | |
* 系统在调用函数时, 这个函数的相关信息都会出现栈之中, 比如参数、返回地址和局部变量 | |
* 入栈顺序和函数内的变量申明顺序可能不一样, 这和编译器有一定的关系 | |
* 所以不能通过一个函数内的多个变量在栈中的地址来判断栈的增长方向 | |
* | |
* 当它调用另一个函数时, 在它栈信息保持不变的情况下会把它调用那个函数的信息放到栈中 | |
* 两个函数的相关信息位置是固定的, 肯定是先调用的函数其信息先入栈, 后调用的函数其信息后入栈 | |
* 这样通过函数栈来确定栈的增长顺序 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 定位new | |
*/ | |
#include <iostream> | |
using namespace std; | |
char g_addr[100]; | |
int main() { | |
// 把内存分配到全局区 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 指针的标准定义方法: | |
* type *ptr; | |
* int val; int *ptr = &val; | |
* int* val; int* *ptr = &val; | |
* 所以不论几级指针都一样, 指针就是*ptr, 一级指针type是int, 二级指针type是int*, 以此类推. | |
* | |
* 同理指向数组的指针: | |
* type *ptr; | |
* int arr[10]; int *ptr = arr; |
NewerOlder