#include <stdio.h>
void fun(char *p) {
if (p) {
printf("%c", *p);
p++;
}
}
int main() {
fun("Y32Y567");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Output:Y
Expected Output:Y32Y567
My questions why it is not working the expected way?
#include<stdio.h>
int main()
{
int a=0, b=1, c=3;
*((a) ?&b :&a) = a ? b : c;
printf("%d %d %d\n", a, b, c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:3 1 3
赋值运算符的结合性是从右到左。所以这里我们得到了 3 1 3 但是......
#include<stdio.h>
int main()
{
int a=0, b=1, c=3;
*((a++) ?&b :&a) = a ? b : c;
printf("%d %d %d\n", a, b, c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:1 1 3
My doubt is why 1 1 3 is returned instead of 1 3 3 ?
Run Code Online (Sandbox Code Playgroud) c postfix-mta variable-assignment conditional-operator postfix-operator
我是 C++ 新手
我的问题是
我知道 unordered_map 使用散列,而 map 使用红黑树。但我很困惑,为什么 unordered_map 需要散列,而 map 不需要。可能是什么原因?
#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
int main()
{
unordered_map<pair<int, int>, int, hash_pair> hmap1;
hmap1[{1,1}]=2;
if (hmap1.find({1,1})!=hmap1.end()) cout<<"Value found :"<<hmap1[{1,1}]<<endl;
if (hmap1.find({0,0})==hmap1.end()) cout<<"Value not found"<<endl;
map<pair<int, int>, int> hmap2;
hmap2[{2,2}]=4;
if (hmap2.find({2,2})!=hmap2.end()) cout<<"Value found :"<<hmap2[{2,2}]<<endl;
if (hmap2.find({0,0})==hmap2.end()) cout<<"Value not …Run Code Online (Sandbox Code Playgroud)