# error in for loop using long long

#1

i am encountering error in this line of the code
for(i = 0; i < length; ++i)
{
scanf("%d",&arr*);
}
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

#2

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

#3

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.

#4

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 .

#5

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.

#6

#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
“,length);
if(arr)
{
for(i = 0 ; i < length; ++i)
{
scanf(”%llu”,&arr
);
if(i > 10000)printf("crossed 10000
");
}
i have checked problem starts when i cross around 5000 or less so i still can not figure why.

#7

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.

#8

length is also long long type

#9

Could you post some more code for this question ??

#10

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

#11

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

#12

do not know why is the code being printed like this

#13

#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
“,length);
if(arr)
{
for(i = 0 ; i < length; ++i)
{
scanf(”%llu”,&arr
);
if(i > 10000)printf("crossed 10000
");
}
i have checked problem starts when i cross around 5000 or less so i still can not figure why.

#14

Thank you,it worked!