What is the difference between float and double?

I've read about the difference between double precision and single precision. However, in most cases, float and double seem to be interchangeable, ie using one or the other does not seem to affect the results. Is this really the case? When are floats and doubles interchangeable? What are the differences between them? Huge difference. As the name implies, a double has 2x the precision

float和double有什么区别?

我读过有关双精度和单精度之间的区别。 但是,在大多数情况下, float和double似乎是可以互换的,即使用其中一个或另一个似乎不会影响结果。 这是真的吗? 浮动和双打何时可以互换? 他们之间有什么不同? 巨大的差异。 顾名思义, double精度float的精度是2x [1]。 通常, double有15位精度的小数位,而float有7位。 以下是计算数字的方式: double有52个尾数位+ 1个隐藏位:log(253)÷log(10)= 15.95位 floa

Difference between private, public, and protected inheritance

What is the difference between public , private , and protected inheritance in C++? All of the questions I've found on SO deal with specific cases. To answer that question, I'd like to describe member's accessors first in my own words. If you already know this, skip to the heading "next:". There are three accessors that I'm aware of: public , protected and private

私人,公共和受保护继承的区别

C ++中public , private和protected继承之间的区别是什么? 我在SO上发现的所有问题都涉及特定案例。 为了回答这个问题,我想先用我自己的话来描述成员的访问者。 如果您已经知道这一点,请跳至标题“下一步:”。 我知道有三种访问者: public , protected和private 。 让: class Base { public: int publicMember; protected: int protectedMember; private: int privateMember;

What is Dynamic Memory Allocation in C++?

I'm learning about Dynamic Memory Allocation in C++ and the keywords new and new[] are mentioned. It is said to enable users to specify the size of the memory allocation at runtime, unlike simply declaring a variable or array with a fixed size in the source code. I don't understand this concept. How does it work? I just need a clarification on the idea and an example would be helpful

什么是C ++中的动态内存分配?

我正在学习C ++中的动态内存分配,并提到了new和new[]关键字。 据说使用户能够在运行时指定内存分配的大小,而不像在源代码中只声明一个固定大小的变量或数组。 我不明白这个概念。 它是如何工作的? 我只需要澄清一下这个想法,一个例子会很有帮助! 所以,如果你想要一个10个整数的数组,你会写: int arr[10]; 但是如果你想做这样的事情呢? cout << "How many?"; cin >> num; int arr[num]; 那么,

In what cases do I use malloc vs new?

I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc you should call free and when you use the new operator you should pair with delete and it is a mistake to mix the two (eg Calling free() on something that was created with the new operator), but I'm not clear on when I should use malloc / free and when I should use new / delete in my real

我在哪些情况下使用malloc vs new?

我在C ++中看到有多种分配和释放数据的方法,我知道当你调用malloc时应该free调用,当你使用new操作符时,你应该配对delete ,混合两者是错误的(例如,Calling free()用new操作符创建的东西),但我不清楚什么时候应该使用malloc / free ,何时应该在我的真实世界程序中使用new / delete 。 如果您是C ++专家,请告诉我您在这方面遵循的任何规则或惯例。 除非你被迫使用C,否则不应该使用 malloc 。 始终使用new 。 如果

Is there a program to convert assembly to C++?

Is there a program that will convert assembly to C or C++? I did a lot of searching but I could not find anything that works. There is a program called "Boomerang"; it looks great and just want I wanted, but it's very unstable and crashes when I try to use it. (boomerang) Are there any other free programs that will do that? What you're looking for is a decompiler. You

有没有程序将程序集转换为C ++?

是否有程序可以将程序集转换为C或C ++? 我做了很多搜索,但找不到任何有用的东西。 有一个名为“回旋镖”的程序; 它看起来很棒,只是想要我想要的,但是当我尝试使用它时,它非常不稳定并且崩溃。 (飞去来器) 有没有其他免费程序可以做到这一点? 你正在寻找的是一个反编译器。 你最终会得到比ASM资源更好的东西,而且我相信你最终会用C而不是C ++。 有很少的工具能够进行转换,如从ASM到C的Regolix转换器,以及将A

Why don't C++ compilers define operator== and operator!=?

I am a big fan of letting the compiler do as much work for you as possible. When writing a simple class the compiler can give you the following for 'free': A default (empty) constructor A copy constructor A destructor An assignment operator ( operator= ) But it cannot seem to give you any comparison operators - such as operator== or operator!= . For example: class foo { publi

为什么C ++编译器不定义运算符==和运算符!=?

我非常喜欢让编译器尽可能为您做很多工作。 当编写一个简单的类时,编译器可以为你提供以下'免费': 默认(空)构造函数 复制构造函数 析构函数 赋值运算符( operator= ) 但它似乎无法给你任何比较运算符 - 比如operator==或operator!= 。 例如: class foo { public: std::string str_; int n_; }; foo f1; // Works foo f2(f1); // Works foo f3; f3 = f2; // Works if (f3 =

Iterator invalidation rules

What are the iterator invalidation rules for C++ containers? Preferably in a summary list format. (Note: This is meant to be an entry to Stack Overflow's C++ FAQ. If you want to critique the idea of providing an FAQ in this form, then the posting on meta that started all this would be the place to do that. Answers to that question are monitored in the C++ chatroom, where the FAQ idea star

迭代器失效规则

什么是C ++容器的迭代器失效规则? 最好以摘要列表格式。 (注意:这是一个Stack Overflow的C ++常见问题解答的入口,如果你想批评在这个表单中提供常见问题的想法,那么开始所有这些的meta上的贴子将成为这样做的地方。那个问题在C ++聊天室中进行监控,常见问题的想法首先出现在C ++聊天室中,所以你的答案很可能会被那些提出这个想法的人阅读。) C ++ 03 (来源:迭代器失效规则(C ++ 03)) 插入 序列容器 vec

How does the compilation/linking process work?

How does the compilation and linking process work? (Note: This is meant to be an entry to Stack Overflow's C++ FAQ. If you want to critique the idea of providing an FAQ in this form, then the posting on meta that started all this would be the place to do that. Answers to that question are monitored in the C++ chatroom, where the FAQ idea started out in the first place, so your answer is ver

编译/链接过程如何工作?

编译和链接过程如何工作? (注意:这是一个Stack Overflow的C ++常见问题解答的入口,如果你想批评在这个表单中提供常见问题的想法,那么开始所有这些的meta上的贴子将成为这样做的地方。那个问题在C ++聊天室中进行监控,常见问题的想法首先出现在C ++聊天室中,所以你的答案很可能会被那些提出这个想法的人阅读。) 编译一个C ++程序包括三个步骤: 预处理:预处理需要花费C ++源代码文件,并处理所述#include S, #def

Undefined behavior and sequence points

What are "sequence points"? What is the relation between undefined behaviour and sequence points? I often use funny and convoluted expressions like a[++i] = i; , to make myself feel better. Why should I stop using them? If you've read this, be sure to visit the follow-up question Undefined behavior and sequence points reloaded. (Note: This is meant to be an entry to Stack

未定义的行为和顺序点

什么是“序列点”? 未定义行为和序列点之间的关系是什么? 我经常使用有趣而令人费解的表达式,如a[++i] = i; ,让自己感觉更好。 为什么我应该停止使用它们? 如果您已阅读此内容,请务必访问后续问题重新加载未定义的行为和顺序点。 (注意:这是一个Stack Overflow的C ++常见问题解答的入口,如果你想批评在这个表单中提供常见问题的想法,那么开始所有这些的meta上的贴子将成为这样做的地方。那个问题在C ++聊天室

What is The Rule of Three?

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied? Introduction C++ treats variables of user-defined types with value semantics. This means that objects are implicitly copied in various contexts, and we should understand what "copying an object" a

什么是三项规则?

复制对象意味着什么? 什么是复制构造函数和复制赋值运算符? 我什么时候需要自己申报? 我怎样才能防止我的对象被复制? 介绍 C ++用值语义处理用户定义类型的变量。 这意味着对象被隐式复制到各种上下文中,我们应该理解“复制对象”实际上意味着什么。 让我们考虑一个简单的例子: class person { std::string name; int age; public: person(const std::string& name, int age) : name(name), age