How to fix the Segmentation fault (core dumped) in C++?

Advertisements I’m writing a program that combines 2 vectors and sorts them and then prints the vector but I’m not using a third vector. Instead I’m combining one vector with another and then sorting the combined vector. But I get a error called "Segmentation fault". here’s the code: #include<bits/stdc++.h> using namespace std; int main() {… Read More How to fix the Segmentation fault (core dumped) in C++?

Replacing decayed array with a pointer to array resulting in segmentation fault

Advertisements I was trying to loop through an array using pointers: #include <iostream> #include <iterator> int main() { char name[]{ "Abhi" }; for (char* ptr_c{ name }; ptr_c != (ptr_c + std::size(name)); ++ptr_c) { std::cout << *ptr_c; } std::cout << "\n"; } This results in: Error: Segmentation fault core dumped However, in the for loop’s… Read More Replacing decayed array with a pointer to array resulting in segmentation fault

I have to write a program which accepts n number of integers and display the degree of the array

Advertisements I’ve been trying to code this for the last hour but I keep on getting "segmentation error". I’m still very new to C so please don’t be too harsh. Can anybody help? Here is my code: input:4 2 4 2 2 5 6 output: 3 #include<stdio.h> #include<stdlib.h> int degreeOfArray(int arr[], int n) { int… Read More I have to write a program which accepts n number of integers and display the degree of the array

I cannout out why I get the error "core dumped" C++

Advertisements I don’t know why when I run this piece of code : #include <iostream> #include <cstring> class Masina{ private: long long putere; int viteza; double masa; bool calificativ; char* nume; public: Masina();//constuctor default Masina(long long putere,int viteza,double masa,bool calificativ,char* nume);//constructor supraincarcat ~Masina();//destructor // Masina(const Masina&) = delete; // setter-e void setPutere(long long putere); void… Read More I cannout out why I get the error "core dumped" C++