error in for loop using long long

i am encountering error in this line of the code
for(i = 0; i < length; ++i)
{
scanf("%d",&arr[i]);
}
where i is long long type and arr is array of int.problem is it does work for i below 1000 but not for larger i like 10000.Do not know what is the problem .if problem is not with this line of code then tell the reason i might get error

Please post your code here so as to have unambiguous and to-the-point replies.

Here the variable length and i both should be long long. By the way please provide some more code to answer this question up to the point. And moreover it depends on array definition. Please provide some more code so that you can get a positive reply.

you could have defined length to be of small value …also .since i is of long long , “length” should also be of long long i guess .

If I understood your problem right! Array size of more than 10^5 inside a function will give you SIGSEGV on Codechef. I am assuming you are using long long int to declare a large sized array in program flow. Try declaring the array globally and that to within a size of 10^6 or so. Anyways give the complete error details.

#include<stdlib.h>
#include<stdio.h>

int main()
{
long long length = 0;
long long *arr ;long long i = 0;
long long zero_pro_len = 0;
long long temp_length = 0;
scanf("%llu",&length);
printf(“size of int is %d”,sizeof(int));
arr = (int *)malloc(sizeof(length));
printf(“length is %llu\n”,length);
if(arr)
{
for(i = 0 ; i < length; ++i)
{
scanf("%llu",&arr[i]);
if(i > 10000)printf(“crossed 10000\n”);
}
i have checked problem starts when i cross around 5000 or less so i still can not figure why.

Since you have declared your array of type long long but you are using a pointer of type int while allocating the memory, it is allocating memory in steps of 2/4 bytes as per your compiler.

Use arr=(long long *)malloc(length * sizeof(long long));
See if it works.

length is also long long type

Could you post some more code for this question ??

length has to be of the type long long otherwise the loop wont run beyond 100000.

adding more code be violation but i am posting some upper part.actually i am solving first problem and upper limit on N is 100000 so i am using long long. well the portion of code is posted in answer

do not know why is the code being printed like this

#include<stdlib.h>
#include<stdio.h>

int main()
{
long long length = 0;
long long *arr ;long long i = 0;
long long zero_pro_len = 0;
long long temp_length = 0;
scanf("%llu",&length);
printf(“size of int is %d”,sizeof(int));
arr = (int *)malloc(sizeof(length));
printf(“length is %llu\n”,length);
if(arr)
{
for(i = 0 ; i < length; ++i)
{
scanf("%llu",&arr[i]);
if(i > 10000)printf(“crossed 10000\n”);
}
i have checked problem starts when i cross around 5000 or less so i still can not figure why.

Thank you,it worked!