Category : variables

When i run the code it outputs the yes even if the number is not present.. int a[6] = {1,2,3,4,5,6}; int n,x,i=0; cin >> x; n = 6; a[n] = x; while(a[i]!=x) i++; if(i==n) cout << "no" ; else cout << "yes" << i; But if i initialize X before the array it gives the ..

Read more

If I wanted to have variables, says ints, called num0, num1, num2 and num3, is there a way to automate that infinitely? So in a for(int i=0;i<4;i++) loop, have the ‘i’ somehow name the variables? This isn’t exactly what I need it for but if this is possible then it would be very helpful. Thank ..

Read more

I need to test some code, and methods accepts pointers to objects. As I want to write many tests, simplified my tests looks like this bool addPoint(Point* point); EXPECT_TRUE(addPoint(&Point(0, 0, 0))); EXPECT_TRUE(addPoint(&Point(-10, 0, 0))); EXPECT_TRUE(addPoint(&Point(0, -10, 0))); //and so on It works fine. I know that taking address of the temporary variable isn’t a good ..

Read more

I am getting this strange problem and couldn’t figure out the reason. The same code was use in several programs. This problem only happens in one of them. And I cannot depulicate the problem in a simplified test program. The problem happens only to the first element of the array. int arrX[30]; // arrX is ..

Read more

i am wondering why if i have code like this: class Test2 { public: Test2() { std::cout << "TEST2 Constructorn"; } ~Test2() { std::cout << "TEST2 Destructorn"; } }; class Test { public: static Test2& get() { static Test2 test{}; return test; } }; int main() { auto test = Test::get(); std::cout << "Createdn"; auto ..

Read more