2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by pikkas
Featured Replies
  • 1
    Narue 5,707   7 Years Ago

    >How can i give the values programatically and not by user selection? That's even easier. Just replace scanf with an assignment to nv of whatever expression you want: [code=cplusplus] nv = 5; /* allocate memory for the adjacency memory */ adj_matrix = (int**)malloc(sizeof(int*) * nv); [/code] Read More

0

Each one designate a level of indirection (a pointer). So you can say that adj_matrix is a pointer to a pointer to int. My spidey sense says that adj_matrix is intended to be a dynamically allocated adjacency matrix, so you can do a google search for dynamic arrays in C++ for further details (or ask another specific question here).

0

i have these code which give values to adj_matrix from scanf value which give the user the choice to select the value.

printf("Enter the number of vertices\n");
    scanf("%d",&nv);
	
	/* allocate memory for the adjacency memory */
	adj_matrix = (int**)malloc(sizeof(int*) * nv);

How can i give the values programatically and not by user selection?.

1

>How can i give the values programatically and not by user selection?
That's even easier. Just replace scanf with an assignment to nv of whatever expression you want:

nv = 5;

/* allocate memory for the adjacency memory */
adj_matrix = (int**)malloc(sizeof(int*) * nv);
0

i have tried it already but i get an error
error: syntax error before "adj_matrix"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.