Why do I get a SIGSEGV?

getting SIGSEV onthis piece of code which is from the beginner fctrl problem

#include
using namespace std;
int main()
{
int num,n=1,zeroes=0,power=5;
cin>>num;
int i,j,k,arr[1000],res[1000];
for(i=0;i<num;i++)
{
cin>>arr[i];
}
for(j=0;j<num;j++)
{
zeroes=0;
power=5;
while((arr[j]/power)>0)
{
zeroes+=(arr[j]/power);
n++;
power*=5;
}
res[j]=zeroes;
}
for(k=0;k<num;k++)
cout<<res[k]<<endl;
return 0;
}

please help tried to write a very precise piece of code but it seems not to be working help;

why do i get SIGSEVAG for this code ?
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int m,n,i,indices,count=0;
cin>>n>>m;
int a[n]={0};
while(m–){
cin>>indices;
a[indices-1]=1;
}

	  for(i=0;i<n;i++){
	  	if(a[i]!=1){
		  
	  	count++;
	  	if(count%2==0&&count!=0)
	  	a[i]=3;
	  	if(count%2==1)
	  	a[i]=4;		     
	  }
}
	  
	for(i=0;i<n;i++){
		if(a[i]==4)
		cout<<i+1<<" ";

}
cout<<endl;
for(i=0;i<n;i++){

		if(a[i]==3)
		cout<<i+1<<" ";
	}
	cout<<endl;
}
return 0;

}

@vineeta1995
.Condition if(t[I]℅k==0)
Will give run time error if value of k=0;

@ankittt_jain you have declared array a[n]
If the value of n goes above 10^6 then you will get run time error.

please help why do i get SIGSEVG for this code
https://www.codechef.com/viewsolution/10818136

You can check here for all errors that mostly occurs at codechef https://www.codechef.com/wiki/status-codes

SIGSEGV : A SIGSEGV is an error(signal) caused by an invalid memory reference or a segmentation fault. You are probably trying to access an array element out of bounds or trying to use too much memory. Some of the other causes of a segmentation fault are : Using uninitialized pointers, dereference of NULL pointers, accessing memory that the program doesn’t own

@gokul95
“solution is CodeChef: Practical coding for everyone

You are getting SIGSEGV becuase you have take character pointer char* a and inputting directly into “a” by using scanf(“%s”,a); This is wrong. “a” is a pointer and has no memory alocated to it. You should first allocate memory to the pointer using malloc before taking inout.
a=(char* )malloc(sizeof(char)*SIZE)
where SIZE is the maximum input lenght of string + 1(1 extra for ‘\0’).
Just add this line before your scanf line.

I have tried many things and this code runs fine on my computer but on submitting I repeatedly get SIGSSEVG ?? You can check here.CodeChef: Practical coding for everyone

why do i get sigsevg for this code
https://www.codechef.com/viewsolution/11028794

why do i get sigsevg for the code : CodeChef: Practical coding for everyone

Go to Help—> FAQ
You get most of your answer there.

This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an array element out of bounds, or using too much memory.

Some things for you to try:

Make sure you aren’t using variables that haven’t been initialised. These may be set to 0 on your computer, but aren’t guaranteed to be on the judge.

Check every single occurrence of accessing an array element and see if it could possibly be out of bounds.

Make sure you aren’t declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work.

Make sure you aren’t declaring too much stack memory. Any large arrays should be declared globally, outside of any functions - putting an array of 100000 ints inside a function probably won’t work.

As [wikipedia][1] says

“It is an fault raised by hardware informing your operating system about memory access violation , for which os kernel in return generate a signal to the offending process , called SIGSEGV (or Core dumped).”

But in simple terms

"These errors are generated if any pointer(like in C language that provide low level memory access) is trying to access a memory location which has not been allocated to the program , or your program is trying to use memory which are not for the program "
[1]: Segmentation fault - Wikipedia

getting runtime SIGSEVG on this, don’t know why

https://www.codechef.com/viewsolution/11194997

why am i getting SIGSEV for this solution?

CodeChef: Practical coding for everyone.

what can i really do in order to remove it?

i am getting sigsegv in this code CodeChef: Practical coding for everyone
for this problem TSORT Problem - CodeChef
pls help

#include<stdio.h>
#include<stdlib.h>
int main(int argc,char * argv[])
{
int i,j,m, T,reverse=0;
// int arr[200];
int n[200];
T=atoi(argv[1]) ;
if(!((1<=T)&&(T<=1000)))
{
exit(0); //checking if T is not greater than 1000 and not less than 1
}
for(i=0,j=2;j<T+2;i++,j++)
{
n[i] = atoi(argv[j]) ;
if(!((1<=n[i])&&(n[i]<=100000) )) //checking if n is not greater than 100000 and not less than 1
{
exit(0); //(0 <= i) && ( i<=10)
}
}
/* printf("%d\n",T);

for(m=0;m<T;m++)
{
printf("%d\n",n[m]);
}
*/

for (m=0;m<T;m++)
 {
     reverse=0;
     while(n[m] != 0)
  {
  	 reverse = reverse * 10;
  	 reverse = reverse + (n[m] % 10 );
  	 n[m] = n[m] / 10;
  }
//printf("%d\n",n[m]);
	
printf("%d\n",reverse);

  }

return 0;
}

why m getting sigsegv

#include <stdio.h>
#include<stdlib.h>
int *intArray,n ;

void display(){
int i;
// navigate through all items
for(i = 0;i<n;i++){
printf("\n%d ",intArray[i]);
}
}

void swap(int num1, int num2){
int temp = intArray[num1];
intArray[num1] = intArray[num2];
intArray[num2] = temp;
}

int partition(int left, int right, int pivot){
int leftPointer = left -1;
int rightPointer = right;

while(1){

  while(intArray[++leftPointer] < pivot){
     //do nothing
  }
	
  while(rightPointer > 0 && intArray[--rightPointer] > pivot){
     //do nothing
  }

  if(leftPointer >= rightPointer){
     break;
  }else{
     swap(leftPointer,rightPointer);
  }

}
swap(leftPointer,right);
return leftPointer;
}

void quickSort(int left, int right){
if(right-left <= 0){
return;
}else {
int pivot = intArray[right];
int partitionPoint = partition(left, right, pivot);
quickSort(left,partitionPoint-1);
quickSort(partitionPoint+1,right);
}
}

int main(){
int i;
scanf("%d",&n);
intArray=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++)
scanf("%d",intArray[i]);
quickSort(0,n-1);
display();
free(intArray);
return 0;
}
questions:–
All submissions for this problem are available.

Given the list of numbers, you are to sort them in non decreasing order.
Input

t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order.
Example

Input:

5
5
3
6
7
1
Output:

1
3
5
6
7
why i am getting fragmentation error.?

why am i getting SIGEGV for this program CodeChef: Practical coding for everyone

whats wrong in this code. can some one help me out https://www.codechef.com/viewsolution/11554582