[Solved] Dynamic Memory allocation fault

The issue is that n keeps growing, but your array does not. This code invokes undefined behavior, which thankfully caused a segfault for you: while(ch==’y’) { n++; cout<<“Enter 1 more element: “; cin>>arr[n]; cout<<“Want to enter more? “; cin>>ch; } arr has only been allocated to store n elements. Simply writing past the end will … Read more

[Solved] Passing to a same function matrices with different sizes of both dimensions

You should use a typedef so that you don’t have to use any awful syntax: using matrix_t = int[3][3]; And you should pass your args by reference whenever possible: void handle_matrix(const matrix_t &mat){ // do something with ‘mat’ } If you want to use the original syntax without a typedef: void handle_matrix(const int (&mat)[3][3]){ // … Read more

[Solved] Delete query to delete data from multiple tables in sql server and c#

Like this? It seems easiest just to do it as three separate statements. DELETE FROM Products WHERE SubCatId IN (SELECT SubCatID FROM SubCategory WHERE MainCatId = @mainCatId); DELETE FROM SubCategory WHERE MainCatId = @mainCatId; DELETE FROM MainCategory WHERE MainCatId = @mainCatId; 8 solved Delete query to delete data from multiple tables in sql server and … Read more

[Solved] How to set a matrix as a parameter to a function

You can represent the matrix as a vector<vector<int> >. Try something like this: #include <vector> using namespace std; void myFunction(const vector<vector<int> >& matrix) { // do something w/ matrix passed in… } int main() { // create a 3×4 matrix initialized to all zero const size_t rowCount = 3; const size_t colCount = 4; vector<vector<int> … Read more

[Solved] Combine two integers (one containing the integer part, the other the decimal part) into a floating point number

Cheating solution goes like this: string number = wholeNumber + “.” + decimal double doubleNumber = Double.Parse(number); Clean solution would involve checking how many values you have in the ‘decimal’, dividing by 10^amount and adding them As was pointed out – decimal seperator is cultural-specific – so the completly correct version is string number = … Read more

[Solved] wildly different behaviour between O2 and O3 optimized FP code [closed]

From GCC manual: -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options. No of these optimizations are particularly unsafe. The only optimization that I see can change the result is -ftree-vectorize. In some cases, using vector instructions … Read more

[Solved] not able to compile code with “std::pair” [closed]

You cannot declare a member variable of a class like that. Declare it as: typedef std::pair <int, int> MyMove; static const MyMove my_no_move; And then define it outside the class as: // The typedef MyMove is also scoped const ConnectFourState::MyMove ConnectFourState::my_no_move(-1, -1); 3 solved not able to compile code with “std::pair” [closed]

[Solved] if statement in a foreach loop c# [closed]

You dealing with type string not char. So update single quotes to double quotes: foreach (User user in this.oSkype.Friends) { if (user.OnlineStatus == “olsOffline”) { this.listBoxControl1.Items.Add(user.Handle + ” Offline”); } else { this.listBoxControl1.Items.Add(user.Handle + ” Online”); } } 1 solved if statement in a foreach loop c# [closed]

[Solved] Output of Nested printf and scanf in C [closed]

I think what you are missing is, your one line with nested function calls is basically same as this code: int scanf_result = scanf(“%d%d,”,&i,&a); int printf_result = printf(“PRINT %d\t”, scanf_result)); printf(“%d”, printf_result); scanf call should return 2 if you entered valid input, but can also return -1 for actual error, or 0 or 1 if … Read more

[Solved] Transform std::pair to std::tuple with any number of elements

Option #1 #include <cstddef> #include <type_traits> #include <utility> #include <tuple> template <typename A, typename B> struct merge_tuples { static_assert(std::tuple_size<A>::value == std::tuple_size<B>::value, “!”); template <std::size_t… Is> static auto merge(std::index_sequence<Is…>) noexcept -> std::tuple<typename std::decay<decltype(std::declval<typename std::tuple_element<Is, A>::type>() + std::declval<typename std::tuple_element<Is, B>::type>()) >::type…>; using type = decltype(merge(std::make_index_sequence<std::tuple_size<A>::value>{})); }; DEMO Option #2 #include <type_traits> #include <utility> template <typename A, typename … Read more

[Solved] How to optimize and speed up this operation

List<Customer> customers = GetCustomers(“ACT”); Task[] tasks = new Task[MaxNumOfConcurrentSaves]; While(customers.Length > 0) { for(int i = 0; i < MaxNumOfConcurrentTasks; i++){ tasks[i] = SaveCustomerData(customers[i]); customers[i] = null; } customers = List.FindAll<Customer>(customers, aCust => !(aCust == null)); Task.AwaitAll(tasks) } Ok so here’s whats happening (and you’ll have to perfect it for your uses): while we have … Read more