Linked Questions

343 votes
21 answers
24k views

I know the uninitialized local variable is undefined behaviour(UB), and also the value may have trap representations which may affect further operation, but sometimes I want to use the random number ...
ggrr's user avatar
  • 7,907
243 votes
14 answers
24k views

I have recently started to learn C and I am taking a class with C as the subject. I'm currently playing around with loops and I'm running into some odd behaviour which I don't know how to explain. #...
JonCav's user avatar
  • 1,667
142 votes
6 answers
18k views

The following code goes into an infinite loop on GCC: #include <iostream> using namespace std; int main(){ int i = 0x10000000; int c = 0; do{ c++; i += i; ...
Mysticial's user avatar
  • 473k
86 votes
4 answers
6k views

I have come across the below C++ program (source): #include <iostream> int main() { for (int i = 0; i < 300; i++) std::cout << i << " " << i * 12345678 << ...
arpanmangal's user avatar
  • 1,798
62 votes
8 answers
5k views

I just had an exam in my class today --- reading C code and input, and the required answer was what will appear on the screen if the program actually runs. One of the questions declared a[4][4] as a ...
Santi Santichaivekin's user avatar
75 votes
4 answers
6k views

I have the following code: #include <iostream> #include <complex> using namespace std; int main() { complex<int> delta; complex<int> mc[4] = {0}; for(int di = 0; ...
eivour's user avatar
  • 1,787
17 votes
4 answers
3k views

Till now I was believing that there is no use of unary + operator. But then I came across with following example: char ch; short sh; int i; printf("%d %d %d",sizeof(ch),sizeof(sh),sizeof(i))...
A.s. Bhullar's user avatar
  • 2,808
25 votes
2 answers
10k views

It's said that infinite loop for(;;); is undefined behavior. From http://en.cppreference.com/w/cpp/language/memory_model In a valid C++ program, every thread eventually does one of the following: ...
cshu's user avatar
  • 5,994
10 votes
5 answers
5k views

I thought that unsigned int could store only integers >= 0. But I tried assigning a negative to an unsigned int, nothing special happened. It seems like it stored the value with no problem. So what ...
Danny's user avatar
  • 125
16 votes
2 answers
9k views

I'm sorry if this is a uber-easy concept, but I find hard to acquire the right mindset in order to correctly use the sanitizer provided by clang. float foo(float f) { return (f / 0); } I compile this ...
user2485710's user avatar
  • 9,891
4 votes
6 answers
6k views

I've written this C code for finding the sum of all integers which are equal to the sum of the factorial of their digits. It takes a minute or so to get the job done without any GCC optimization flags,...
BojanV03's user avatar
5 votes
2 answers
1k views

long long r = 0; long long k = 0; for (; k < 9999999999999; k++) { for (long long i = 0; i < 9999999999999; i++) { for (long long j = 0; j < 9999999999999; j++) { ...
Denis Ermolin's user avatar
13 votes
2 answers
828 views

In this paper is the following example of a piece of code that can trigger a division-by-zero: if (arg2 == 0) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("...
tmyklebu's user avatar
  • 14.3k
2 votes
1 answer
3k views

i'm currently writing a c/c++ dll for later use mostly in Delphi and i'm more familiar with threads in Delphi than c/c++ and especially boost. So i wonder how i can achieve the following scenario? ...
Daniel Mann's user avatar
4 votes
1 answer
5k views

Consider the following code in strange.cpp: #include <vector> using namespace std; int i = 0; int *bar() { ++i; return &i; } int main() { for(size_t j = 0; j < ...
Ami Tavory's user avatar
  • 76.7k

15 30 50 per page