You are here:

C/i need help on memory allocation..

Advertisement


Question
i am only a beginner on memory allocation. we are asked to write a c program that explicitly stores 10 integer values in a one-dimensional array then displays the address of the element..

i made my own code and i don't know if i did it right..

may you please check whether my code is right or not..

if it is incorrect, may you please tell me what to do..

kindly correct my code if i'm wrong..

thanks in advance..  

Answer
Hi Ihie

Firstly I didn't found any code with this question the solution to this is

void main();
{
int *p, i;
//dynamically creating array of 10 int
p = (int*)malloc(sizeof(int)*10);

//iterating using a loop and showing the address
for(i=0;i<10;i++)
printf("%u",(p + i));
}

Please feel free to get back to me in case if you are stuck with this logic.

regards
Joydeep Bhattacharya
http://www.scodz.com

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.