How do you create a really large matrix (i.e. 3500x3500) in C
without having the program crash? I can only reach up to 2500.
It must have something to do with lack of memory. Please help!



How do you create a really large matrix (i.e. 3500x3500) in C without having the program crash? I ..

Answer / gouri shanker m.ojha

using Dynamic memory allocation,you can create large array size.

example:m=1000000,n=1000000
void enter(int m,int n)
{
int i,j;
long int c=0;


matrix=new long int*[m]; /*m is row size*/
for(i=m-1;i>=0;i--)
{
matrix[i]=new long int[n]; /*n is col size*/
for(j=0;j<n;j++)
{
matrix[i][j]=++c;
}
delete matrix[i];
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.

1 Answers  


main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }

2 Answers  


main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O

4 Answers   HCL,


write a c-program to display the time using FOR loop

3 Answers   HCL,


#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?

1 Answers   Wipro,






main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too

1 Answers  


#define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); }

1 Answers  


#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }

1 Answers  


main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above

3 Answers   HCL,


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

0 Answers   IBM,


You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.

3 Answers  


Categories