GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Dumped Core in Basic Problem 2

Here's my code: 

#include<stdio.h>
int a[203];
int main(){
    int t,i;
    scanf("%d",&t);
    for(i = 0;i<t;i++){
        int n,temp,k;
        scanf("%d",&n);
        for(k =0;k<n;k++){
            scanf("%d",&temp);
            a[temp]+=1;
        }
        for(k =0;k<203;k++){
            if(a[k]%2 !=0)
            printf("%d",k);
        }
    }
}

Also, is there any way I can get the code to run in C99 mode?

 

asked Jan 6, 2017 by Mayank Sharma 10

1 Answer

ur inputs in temp

scanf("%d",&temp);

for this program should be 0<=temp<=202, because you are using it as an index at 

 a[temp]+=1;

so any illegal/invalid index can cause segmentation fault/core dump because if you give temp>=203, you are trying to access/change the memory location which is not valid under the range of array "a[203]"

answered Jan 8, 2017 by imlegion
...