Linked Questions
261 questions linked to/from Why should I always enable compiler warnings?
0 votes
1 answer
198 views
Why is C++ implicitly converting 0.0 to some extremly small 'random' value? [duplicate]
I'm trying to compare two class objects, which has both been initialized with 0.0, but for some reason C++ decides to convert the 0.0 to some extremly small value instead of keeping the 0.0, which ...
1 vote
3 answers
80 views
Why is my very basic code that basically only changes a elements value of a array (Error code -1073741819) [duplicate]
The core idea of this is just to have a array of integers and change the value of them based on teminal inputs. This is my very first project and everything seems to be in order but it does not work, ...
-3 votes
1 answer
277 views
What do I add to a 'int read_integer(string prompt)' function so that the program converts this integer into a month [duplicate]
so the 3rd function calls on the read_integer(prompt) from the int read_integer(string prompt) above it, seen by the ***** marks, but I am not sure what to add so that this works. My attempt in the ...
0 votes
1 answer
94 views
Why the difference between char* and char[x] matter when using the & operator [duplicate]
The following code will segfault. char* input = "12.34"; //< this is only to simplify the example. char buffer[30] = { 0 }; memcpy(buffer, input, strlen(input)); char* part1 = strsep(&buffer,...
0 votes
0 answers
55 views
I add Struct Pointer inside the vector and Struct Value has been changed [duplicate]
I'm using raylib to make a little game. and here is the problem. Struct Icon has Loc Struct that has two integer value. When i put the Struct, Icon as a Pointer into Icons vector. value has been ...
0 votes
0 answers
46 views
How to do you create a function that accepts an input and assigns it to a variable? [duplicate]
#include <iostream> using namespace std; string userInput, userName; The function below takes an input from the user string takeInput() { cin.ignore(); getline(cin,...
145 votes
12 answers
55k views
C++ templates Turing-complete?
I'm told that the template system in C++ is Turing-complete at compile time. This is mentioned in this post and also on wikipedia. Can you provide a nontrivial example of a computation that exploits ...
6 votes
2 answers
4k views
C++ reverse 'for' loop
I have a vector: std::vector<int> vec = {1, 2, 3}; And I want to make a reverse for loop. It works, when I write: for(int i = vec.size() - 1; i >= 0; --i) { std::cout << i << ...
4 votes
8 answers
207 views
Word given to the standard in using scanf isn't printed without error
I am trying to printf a simple string but I am not being able to. #include <stdio.h> int main(){ char *word; scanf("%s", &word); printf("%s\n", word); return ...
14 votes
1 answer
531 views
Why is a name's point of declaration before its initializer?
Sayeth the C++ standard: The point of declaration for a name is immediately after its complete declarator and before its initializer (if any)... [basic.scope.pdecl] That is, a variable is in scope, ...
7 votes
2 answers
159 views
In this C Program for some odd reason the 5th line in code prints 1.799999 which doesn't make sense
#include<stdio.h> void main(){ printf("%f\n",5/9); // prints 0.000000 printf("%f\n",9.0/5.0); // prints 1.800000 printf("%f\n",5/9); // prints 1.799999 } ...
4 votes
3 answers
339 views
pass rvalue to std::move and bind rvalue refence to it generate stack-use-after-scope error in ASAN
considering this code snippet #include <iostream> int foo() { int a; return a; } int main() { auto &&ret = std::move(foo()); std::cout << ret; } compile with ASAN g++ -...
2 votes
1 answer
5k views
What does the clang compiler's `-Weverything` option include and where is it documented?
clang, but NOT gcc, has a -Weverything option which appears to include things such as -Wpedantic. You can test it here: https://godbolt.org/z/qcYKd1. See the top-right of the window for where I have ...
2 votes
2 answers
1k views
Why do char arrays get lost when returning from a function in C++?
I know that, if we declare variables inside a function without allocating memory for them, they will be lost after the function finishes its job. The following code prints: (null) 5 char* ...
2 votes
3 answers
2k views
Assigning char array to char array in C
can you help me with this code, i am able to copy arr into arr2(from index 1 and further, i cannot figure index 0 till now), but some others can't. Can you tell if anything's wrong here? #include <...