Posted: Mon Dec 01, 2008 5:03 pm Post subject: C programming help
I'm trying to work on some homework for class and I don't understand what I am supposed to do. Here is the assignment:
Code:
By using a pointer to pointer **A and the function malloc()
allocate the memory for the 4x4 matrix A[][]. By using a pointer *b
and the function malloc() allocate the memory for the 4-dimensional vector
b[]. Read the components of A and b from the given input file matrix.dat.
The last line of the input file contains the components of b. The rows of
matrix A are the first four lines of the input file. Print the components
of A[][] row by row, and the components of b[]. Using the function gauss()
given in the lecture notes week9.txt, solve the system of linear algebraic
equations A[][]*x[]=b[]. Print the components of the solution vector x[].
Calculate and print the length of this vector. Free the allocated memory.
errr... yeah. help if you can please.
is the pointer **A the same thing as the component A? _________________
Posted: Tue Dec 02, 2008 2:18 am Post subject: Re: C programming help
dkimxd wrote:
is the pointer **A the same thing as the component A?
Pointer points to a memory location where the data is stored. Eg. in this case there's a block of 4x4 = 16 components, which you should read from the file and then fill the matrix with them. Having two dimensional pointers just means that there's pointers to pointers, which point to the data. So yea, if you **A can be the same as the FIRST component of the matrix, since * is the dereference operator. Just experiment with pointers and you'll find them handy, here's an example:
Code:
int C = 10;
int *B = &C;
int **A = &B;
printf("C:%x->%d\nB:%x->%x->%d\nA:%x->%x->%x->%d", &C, C, &B, B, *B, &A, A, *A, **A);
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum