vector<int> v(22);
bool b = (v[6]);
printf("%d", !b);
using namespace std;
typedef struct{
unsigned int age : 4;
unsigned char gender : 1;
unsigned int size : 2;
}child_t;
std::vector<int> v1{1,2,3},v2; v2=v1; v1.push_back(4); v2.push_back(5);
std:: vector<int> *v1 = new std::vector<int>({1,2,3}); std:: vector<int> *v2; v2=v1; v1->push_back(4); v2->push_back(5);
*v1:{1,2,3,4}; *v2:{5};
*v1:{1,2,3,4,5}; *v2:{1,2,3,4,5};
*v1:{1,2,3,4}; *v2:{1,2,3,5};
v1 和 v2 指向同一个向量。
typedef struct {
int sunday:1;
int monday:1;
// more days
int friday:1;
int saturday:1;
} weekdays;
typedef char[7]: weekdays;
typedef struct {
bit sunday:1;
bit monday:1;
// more days
bit friday:1;
bit saturday:1;
} weekdays;
typedef struct {
bit sunday;
bit monday;
// more days
bit friday;
bit saturday;
} weekdays;
参考资料 注意:每个变量大小都是 1 位。在 C++ 中,bit
不是一种类型。
auto x = 4000.22;
if(x) y=a; else y=b;
y=a?b:x;
y=if(x?a:b);
y=(x&a)?a:(x&b)?b:0;
y=x?a:b;
#include <iostream>
int main(){
int x=10, y=20;
std::cout << "x = " << x++ << " and y = " << --y << std::endl;
std::cout << "x = " << x-- << " and y = " << ++y << std::endl;
return(0);
}
x = 10 且 y = 20
x = 11 且 y = 19
x = 11 且 y = 19
x = 10 且 y = 20
x = 10 且 y = 19
x = 11 且 y = 20
x = 11 且 y = 20
x = 10 且 y = 19
std::pair
,指定了变量将在其中迭代的范围(起始和结束)。 std::pair
,指定了在循环内访问元素的范围(起始和结束)。 int8_t a=200; uint8_t b=100; if(a>b) std::cout<<"greater"; else std::cout<<"less";
注意:以下是问题的一个变种。
int8_t a=200; uint8_t b=100; std::cout<<"a="<<(int)a; std::cout<<", b="<<(int)b;
注意:从 'int' 到 'int8_t'(也称为 'signed char')的隐式转换会将值从 200 更改为 -56
int x=5, y=2; if(x & y) { /*_part A_*/ } else { /*_part B_*/ }
get_length
函数的有效定义是什么,它返回以 null 结尾的字符串的长度?int get_length(char *str) {
int count=0;
while(str[count++]);
return count-1;
}
int get_length(char *str) {
int count=0;
while(str!=NULL){
count++;
str++;
}
return count;
}
int get_length(char *str) {
int count=0;
while((*str)++)
count++;
return count;
}
int get_length(char *str) {
int count=0;
while(str++)
count++;
return count;
}