Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

memory initialisation for 2d pointers, how to??

Status
Not open for further replies.

cedance

Advanced Member level 2
Advanced Member level 2
Joined
Oct 24, 2003
Messages
551
Helped
30
Reputation
60
Reaction score
7
Trophy points
1,298
Location
Germany
Activity points
4,622
hi,

suppose i have

#....

main()
{
int n=6;(which means i am to generate a 6*6 matrix)
int **a;

and some how i allocated the memory required for 6*6 to the pointer a....

now, how do i initialise the elements of pointer a to "0" so that i can start accessing them as arrays without any junk values... coz, in my program some values r untouched and if i initialise to "0", it wud be fine, with junk its jus disappointing... i hav heard of memset command for 1d pointers, is it possible ot initialise 2d pointers using the same? thk u.

/cedance
 

Hi,
yes you can use memset for 2d pointers, here is how

int arr[10][10];

arr[0][9] = 10;
arr[9][9] = 10;

memset(arr,0,sizeof(int)*10*10);

int a = arr[0][9];
a = 0;
a = arr[9][9];

in your case simply replace the arr with your pointer name, just make sure that you pass the number of bytes correctly to memset depending on the data type of the array you are using.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top