我知道像x++或函数调用这样的表达式不会在 sizeof 运算符中计算。
当我运行下面的代码时,我得到了4 8 8输出。有人可以向我解释第 6、7、8 行实际发生了什么吗?
#include <stdio.h>
int main()
{
int x=10;
double y=10.0;
printf("%d ",sizeof (x=x+y));
printf("%d ",sizeof (y=x+y));
printf("%d ",sizeof (x+y));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我发现如果表达式=隐式地(如预增量)或显式地(如x=x+y)包含赋值运算符,则表达式不会在sizeof运算符中求值。
我对吗?
为什么这样做?
std::function<int(int)> ret_func = [](int x) { return x; };
std::function<std::string(int)> ret_func1 = [](int x) { return std::to_string(x); };
std::function<void(int)> func = ret_func;
std::function<void(int)> func1 = ret_func1;
Run Code Online (Sandbox Code Playgroud)
由于std::function? 中函子的类型擦除?这个转换在任何类型的函数之间都不起作用;例如,如果您更改参数并尝试分配给另一个参数,std::function为什么这不起作用?因为返回值不会改变函子的类型而参数呢?
int c = 0xffffffff;
printf("%x\n", (c) == (0xffffffff));
printf("%x\n", (c >> 1) == (0xffffffff >> 1));
Run Code Online (Sandbox Code Playgroud)
第一个输出是1但第二个输出是0。并c >> 1输出0xffffffff。但为什么?
我找到了这段代码:
std::string(avdInfo_getSystemImagePath(m_avd)
?: avdInfo_getSystemInitImagePath(m_avd))
Run Code Online (Sandbox Code Playgroud)
我只找到了有关条件运算符的信息:http : //www.cplusplus.com/articles/1AUq5Di1/
那是, ?和 : 是分开的。但是,当他们在一起时,这意味着什么?既avdInfo_getSystemImagePath与avdInfo_getSystemInitImagePath回报char*
我是 C 的新手。sizeof(long)返回 8,因为 的大小long是 8 个字节(32 位操作系统为 4 个字节)。
但我想知道为什么sizeof(long long)也是8。不应该是16吗?
#include <stdio.h>
#include <stdint.h>
int main() {
printf("%zu\n", sizeof(unsigned long));
printf("%zu\n", sizeof(unsigned long long));
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我刚刚意识到 PowerShell 可以在字符串和数字之间进行比较,我不明白这一点,因为它们是不同的类型。PowerShell 如何比较它们?
PS C:\> Get-Host | Select-Object Version
Version
-------
5.1.19041.1023
PS C:\> $version = (Get-WmiObject -Class Win32_Product | where name -eq 'AWS Command Line Interface v2').Version
PS C:\> $version
2.0.7.0
PS C:\> $version -is [string]
True
PS C:\> 2.0 -is [double]
True
PS C:\> $version -gt 2.0
True
PS C:\> $version -gt 2.1
False
PS C:\> $version -gt 2.0.9
True
Run Code Online (Sandbox Code Playgroud) let cnt=0;
let i = setInterval(() => {
console.log(cnt++);
},200)
setTimeout(() => {
clearInterval(i);
},2000);Run Code Online (Sandbox Code Playgroud)
当在浏览器中执行时,此代码会记录:-
0 1 2 3 4 5 6 7 8 9
但是当使用 Node 执行时,它会记录:-
0 1 2 3 4 5 6 7 8
这是什么原因呢?
我想知道为什么std::map::erase有一个重载返回一个int代表被删除元素的数量;因此,只要元素是唯一的,那么数字就是1或0。在这种情况下,为什么它不返回bool而不是返回int?
std::map<std::string, std::size_t> containers{
{"map", 1}, {"set", 10}, {"map", 5}, {"vector", 4}, {"array", 7}
};
for(auto const& p : containers)
std::cout << p.first << " " << p.second << '\n';
std::cout << containers.erase("map") << '\n'; // 1
std::cout << containers.erase("map") << '\n'; // 0
for(auto const& p : containers)
std::cout << p.first << " " << p.second << '\n';
Run Code Online (Sandbox Code Playgroud) 我有这个类SmallInt应该表示范围内的正整数值0-255- 包括:
struct SmallInt{
explicit SmallInt(int x = 0) : iVal_( !(x < 0 || x > 255) ? x :
throw std::runtime_error(std::to_string(x) + ": value outbounds!")){}
operator int&() { return iVal_; }
int iVal_;
};
int main(){
try{
SmallInt smi(7);
cout << smi << '\n';
cout << smi + 5 << '\n'; // 7 + 5 = 12
cout << smi + 5.88 << '\n'; // 7.0 + 5.88 = 12.88
smi = 33; // …Run Code Online (Sandbox Code Playgroud) c++ explicit-constructor conversion-operator implicit-conversion
memccpy定义为:
void *memccpy(void *dest, const void *src, int c, size_t n)
Run Code Online (Sandbox Code Playgroud)
我知道整数c被用作按unsigned char类型转换。
然后我想
void *memccpy(void *dest, const void *src, unsigned char c, size_t n)
Run Code Online (Sandbox Code Playgroud)
看起来好多了。有什么理由memccpy必须使用int参数吗?
c ×4
c++ ×4
sizeof ×2
browser ×1
c++11 ×1
javascript ×1
node.js ×1
operators ×1
powershell ×1
setinterval ×1
settimeout ×1
stdmap ×1