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

main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

2 Answers   IBM,


main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }

1 Answers  


#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


how to return a multiple value from a function?

5 Answers   Wipro,


Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector

2 Answers  






How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


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  


C program to print magic square of order n where n > 3 and n is odd

2 Answers   Accenture,


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above

4 Answers   Corporate Society, HCL,


Is this code legal? int *ptr; ptr = (int *) 0x400;

1 Answers  


write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

8 Answers  


Categories