z
The content may still persist right after it returns, but soon will get clobbered by other function calls.
Thomas shelby
subscripted value is neither array nor pointer nor vector when assigning an array element value
Thomas shelby
Can anyone tell what does this error mean
Thomas shelby
Any solutions???
Anonymous
subscripted value is neither array nor pointer nor vector when assigning an array element value
Search for the error in Google. The error message seems pretty obvious. Or share your code. We dont have magic crystal balls to predict the reasons.
Thomas shelby
Search for the error in Google. The error message seems pretty obvious. Or share your code. We dont have magic crystal balls to predict the reasons.
#include<stdio.h> sort(int arr[],int n) { int i,a,b[10],c[10]; a = arr[-1]; for(i=0;i<n;i++) { if(a<=a[i]) b[i]=a[i]; else c[i]=a[i]; } for(i=0;i<n;i++) printf("\n%d&%d",b[i],c[i]); } void main() { int arr[25],n; printf("enter the input:"); scanf("%d",&n); for(int i=0;i<n;i++) { printf("enter the numbers:"); scanf("%d",&arr[i]); } sort(arr,n); }
Thomas shelby
I just tried to split an array and tried to store them in different variables
Thomas shelby
What is arr[-1]?
I want to compare the values of 2 arrays with last no of the array
Anonymous
I want to compare the values of 2 arrays with last no of the array
C/C++ is not python. U are accessing memory you are not supposed to.
Thomas shelby
😬😬sorry am a beginner
klimi
arr[] is just a syntax sugar
Anonymous
I just tried to split an array and tried to store them in different variables
This is not sorting btw. This is a step called partitioning which is usually done in quick sort algorithm. This can however be done on the same array. You dont need different arrays. I can see that u r splitting the arrays. But know that I will not be contiguous for both arrays b and c. If you store an element in b when I is 2 then the corresponding element in c array will have Undefined values. Likewise for other values of I as well. You are ignoring that which is a blunder.
Thomas shelby
subscripted value is neither array nor pointer nor vector when assigning an array element value Why do I get this????
Thomas shelby
If else Block
Anonymous
If else Block
a is not an array. It is an integer. You should use arr[i]. If a function doesnt return a value specify that it returns void. Your sort function doesnt specify one. And main is supposed to return an int.
Arm
Hello First question: Why use an array to define a character variable? Second question: I want the code: Define an array that shows us 19 cells.
Thomas shelby
Sorry I haven't looked at that
Thomas shelby
Sorry Sorry
Thomas shelby
I should have seen through it
Anonymous
wilding, i see the c standard specification says the negative array index is semantically correct, however the result is memory value before the array.
Anonymous
https://stackoverflow.com/questions/3473675/are-negative-array-indexes-allowed-in-c
Anonymous
wilding, i see the c standard specification says the negative array index is semantically correct, however the result is memory value before the array.
This code is perfectly valid. int arr[5]={0,1,2,3,4}; int* ptr = arr+4; //even arr+5 is ok printf("%d", ptr[-1]);
Anonymous
wilding, i see the c standard specification says the negative array index is semantically correct, however the result is memory value before the array.
Which is what I told him in my previous message. I said he is accessing memory that is not part of the array.
Barak|ברק
Hypothetically speaking, Is it possible to write window manager via ncurses? How complicated can it get?
Anonymous
Hypothetically speaking, Is it possible to write window manager via ncurses? How complicated can it get?
Errm ncurses is used to design text based interfaces which run in a terminal emulator. And a window manager is used to manage GUI. I don't see any relation. It is like asking can I program GUIs in C++ using cout statements
Barak|ברק
Can it be TUI? To manage files and etc, but make Linux boot up to it
Anonymous
You could design a ncurses based TUI application and modify the kernel command line parameters to boot into text mode by default and set systemd to start this application after the booting process is completed. The user can then navigate through the interface to use the system. But the functionality would be very limited You would have to worry about how your application is going to display files and so on. How you are going to start processes? Your program would be taking on the role of a shell.
Hamidullo 🇺🇿
Hi guys How to create c++ libraries I was search it from google but I can not found I need full tutorial
z
Simply just write a collection of classes and functions in C++, and bundle it into one project. That will be a library. What exactly do you mean by C++ libraries anyway?
Anonymous
Hi guys How to create c++ libraries I was search it from google but I can not found I need full tutorial
Just source code libraries or compiled libraries? On Linux or on Windows?
z
With source code For linux
Expose your header files and compile your C++ files into a shared object (.so).
Sachin
if ( n & n-1 == 0 ) how will compiler read this
Sachin
like this is am right ( n & ( (n-1) == 0 ) )
Sachin
?
Anonymous
With source code For linux
If you are going to share the source code, you can just bundle them together with the necessary make files like @Mysticial suggested and leave it as it is. The person using your library can include your headers and link against your code. There is no additional work required.
Sachin
?
z
I am going to work with pc drivers
BTW, Linux driver is not userspace program. You need to compile it as kernel object. The extension will be (.ko).
z
And insert/remove it with insmod/rmmod.
z
And probably you need to use C instead of C++. As the kernel API is fully written in C.
z
If you still really want to use C++. You probably can't use STL, as you don't have libc++ in the kernel space.
Sachin
Sachin
Yes
thanks you
Samvel
hi, can anyone explain the functions of the program? (write how they work) #include <iostream> using namespace std; // функция для сортировки методом вставки (по убыванию) void insertionSort_m(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] < temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // функция для сортировки методом вставки (по возрастанию) void insertionSort_b(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] > temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // Функция для слияния отсортированных кусков void merge(int arr[], int l, int m, int r) { int len1 = m - l + 1, len2 = r - m; int left[len1], right[len2]; for (int i = 0; i < len1; i++) left[i] = arr[l + i]; for (int i = 0; i < len2; i++) right[i] = arr[m + 1 + i]; int i = 0; int j = 0; int k = l; while (i < len1 && j < len2) { if (left[i] <= right[j]) { arr[k] = left[i]; i++; } else { arr[k] = right[j]; j++; } k++; } while (i < len1) { arr[k] = left[i]; k++; i++; } while (j < len2) { arr[k] = right[j]; k++; j++; } } void timSort(int arr[], int n, int choise) { for (int i = 0; i < n; i+=32) if(choise == 1) insertionSort_b(arr, i, min((i+32-1),(n-1))); else insertionSort_m(arr, i, min((i+32-1),(n-1))); for (int size = 32; size < n; size = 2*size) { for (int left = 0; left < n; left += 2*size) { int mid = left + size - 1; int right = min((left + 2*size - 1),(n-1)); if(mid < right) merge(arr, left, mid, right); } } } int main() { setlocale(LC_ALL, "Russian"); int size; cout << "Введите размер массива: "; cin >> size; int arr[size]; for(int i=0; i < size; i++){ cout << "arr[" << i << "] = "; cin >> arr[i]; } cout << endl << "Ваш массив: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } int choise; cout << endl << "Каким способом хотите отсортировать массив ?" << endl; cout << "1 - по возрастанию, 2 - по убыванию" << endl; cout << "Ваш выбор: "; cin >> choise; if (choise ==1 || choise ==2) { timSort(arr, size, choise); cout << endl << "Массив после сортировки: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } }else cout << "Вы выбрали неправильный пункт!"; return 0; }
Golden Age Of
hi, can anyone explain the functions of the program? (write how they work) #include <iostream> using namespace std; // функция для сортировки методом вставки (по убыванию) void insertionSort_m(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] < temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // функция для сортировки методом вставки (по возрастанию) void insertionSort_b(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] > temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // Функция для слияния отсортированных кусков void merge(int arr[], int l, int m, int r) { int len1 = m - l + 1, len2 = r - m; int left[len1], right[len2]; for (int i = 0; i < len1; i++) left[i] = arr[l + i]; for (int i = 0; i < len2; i++) right[i] = arr[m + 1 + i]; int i = 0; int j = 0; int k = l; while (i < len1 && j < len2) { if (left[i] <= right[j]) { arr[k] = left[i]; i++; } else { arr[k] = right[j]; j++; } k++; } while (i < len1) { arr[k] = left[i]; k++; i++; } while (j < len2) { arr[k] = right[j]; k++; j++; } } void timSort(int arr[], int n, int choise) { for (int i = 0; i < n; i+=32) if(choise == 1) insertionSort_b(arr, i, min((i+32-1),(n-1))); else insertionSort_m(arr, i, min((i+32-1),(n-1))); for (int size = 32; size < n; size = 2*size) { for (int left = 0; left < n; left += 2*size) { int mid = left + size - 1; int right = min((left + 2*size - 1),(n-1)); if(mid < right) merge(arr, left, mid, right); } } } int main() { setlocale(LC_ALL, "Russian"); int size; cout << "Введите размер массива: "; cin >> size; int arr[size]; for(int i=0; i < size; i++){ cout << "arr[" << i << "] = "; cin >> arr[i]; } cout << endl << "Ваш массив: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } int choise; cout << endl << "Каким способом хотите отсортировать массив ?" << endl; cout << "1 - по возрастанию, 2 - по убыванию" << endl; cout << "Ваш выбор: "; cin >> choise; if (choise ==1 || choise ==2) { timSort(arr, size, choise); cout << endl << "Массив после сортировки: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } }else cout << "Вы выбрали неправильный пункт!"; return 0; }
Names of the functions say it by yourself, here you have 2 variations of sorting algorithm by insertions. Just google it, there are a lot articles which could explain you the principle of that working. You have no need to get deeper with this info, just discover principles how these algorithms are built
Anonymous
hi, can anyone explain the functions of the program? (write how they work) #include <iostream> using namespace std; // функция для сортировки методом вставки (по убыванию) void insertionSort_m(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] < temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // функция для сортировки методом вставки (по возрастанию) void insertionSort_b(int arr[], int left, int right) { for (int i = left + 1; i <= right; i++) { int temp = arr[i]; int j = i - 1; while (j >= left && arr[j] > temp) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } } // Функция для слияния отсортированных кусков void merge(int arr[], int l, int m, int r) { int len1 = m - l + 1, len2 = r - m; int left[len1], right[len2]; for (int i = 0; i < len1; i++) left[i] = arr[l + i]; for (int i = 0; i < len2; i++) right[i] = arr[m + 1 + i]; int i = 0; int j = 0; int k = l; while (i < len1 && j < len2) { if (left[i] <= right[j]) { arr[k] = left[i]; i++; } else { arr[k] = right[j]; j++; } k++; } while (i < len1) { arr[k] = left[i]; k++; i++; } while (j < len2) { arr[k] = right[j]; k++; j++; } } void timSort(int arr[], int n, int choise) { for (int i = 0; i < n; i+=32) if(choise == 1) insertionSort_b(arr, i, min((i+32-1),(n-1))); else insertionSort_m(arr, i, min((i+32-1),(n-1))); for (int size = 32; size < n; size = 2*size) { for (int left = 0; left < n; left += 2*size) { int mid = left + size - 1; int right = min((left + 2*size - 1),(n-1)); if(mid < right) merge(arr, left, mid, right); } } } int main() { setlocale(LC_ALL, "Russian"); int size; cout << "Введите размер массива: "; cin >> size; int arr[size]; for(int i=0; i < size; i++){ cout << "arr[" << i << "] = "; cin >> arr[i]; } cout << endl << "Ваш массив: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } int choise; cout << endl << "Каким способом хотите отсортировать массив ?" << endl; cout << "1 - по возрастанию, 2 - по убыванию" << endl; cout << "Ваш выбор: "; cin >> choise; if (choise ==1 || choise ==2) { timSort(arr, size, choise); cout << endl << "Массив после сортировки: " << endl; for(int i=0; i < size; i++){ cout << arr[i] << " "; } }else cout << "Вы выбрали неправильный пункт!"; return 0; }
This is an implementation of Timsort algorithm. Your array is broken into smaller arrays of size 32 which are sorted using insertion sort and these smaller arrays are merged using merge. If the original array itself has size < 32 then it is sorted using insertion sort. I dont know why the person who wrote this code has two functions for insertion sort one with a m suffix and the other with a b suffix. They are both practically the same.
Anonymous
? What error u are getting?
Anonymous
Then u know how to write 2×2?
Anonymous
U mean code for 2×2 is different from 2734×4? ... how?
Anonymous
I adking how the code is different...productOfTwoNumbers = firstNumber * secondNumber ... just this way...
Anonymous
2x2 or 23345x5 its the same code...
Anonymous
Say here... i dont pm
Anonymous
And i am not your bro :)
Anonymous
Then explain better
Anonymous
Explain your error here...
Apk
Why not just paste the question here?
Anonymous
So hardcode them into variable1 , variable2 if u need it urgently ...
Anonymous
Not pretty but hey as long as the result is as expected :)
Anonymous
U should at least know how to hardcode values into variables... google it
olli
what have you done so far? Where is your code?
Anonymous
Sorry but beginner doesnt mean cannot do a=1; b=2; and print a*b...
Anonymous
So code it...
olli
how would you do it on paper? Once you figured that out, you can code it.
꧁༒𝐀𝐡𝐦𝐚𝐝༒꧂
#include<iostream> using namespace std; class abc { public : static int X; int i; abc(){ i= ++X; } }; int abc::X; main (){ abc m, n ,p; cout<<m.x<<" "<<m.i<<endl; }
꧁༒𝐀𝐡𝐦𝐚𝐝༒꧂
What is output ?
꧁༒𝐀𝐡𝐦𝐚𝐝༒꧂
Please help me