Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#include
main()
{
char *q;
int *ip;
q=(char*)malloc(100);
ip=(int*)q;
free(ip);
}
Posted
Comments
krumia 22-Feb-12 0:48am    
Did you compile and run this? Or are you not having access to a compiler? Or are you making others do your homework for you?

Your instructor gave this homework to you for some reasons. That reasons may include making you understand the underlying concepts of computer programming. But if you act like this you will never able to understand them.

Keep doing like this and you will end up screwed.
udayday 22-Feb-12 1:26am    
is this look like a homework
am keep trying this one since yesterday i referred so many blogs
finally i got nothing
let me tell u am not a pro in C
and its a genuine doubt it may useful to others

1 solution

The 'result' is nothing displayed on screen. (I'll assume that #include refers to stdio.h, otherwise the result is a bunch of compiler errors)

Once running, you allocate memory for 100 chars. You then copy a pointer to this memory block into (a) *q and (b) *ip.

You free the memory you allocated and exit program.


I should mention the need to declare main as returning an int (unless you're using a compiler that was around when dinosaurs walked the earth)
 
Share this answer
 
Comments
Varun Sareen 22-Feb-12 0:38am    
good one. take my 4
udayday 22-Feb-12 0:49am    
i used Stdio.h lib function

but am getting compiler errors as ->Function 'malloc' should have a prototype. ->Function 'free' should have a prototype. ->can not convert 'int *' to 'int'
enhzflep 22-Feb-12 0:50am    
What compiler are you using? Is it 'Turbo' anything?
udayday 22-Feb-12 1:12am    
ya mine "Turbo "
enhzflep 22-Feb-12 1:37am    
I suggest you place it atop a large stack of wood, douse with liquid hydrocarbons before setting the pyre alight!

The Turbo C/ Turbo C++ compilers are _very_ old now. They're only 16 bit amongst other problems. That's also the reason they continue to allow main to have no return type..

I suggest you get a copy of MinGW. You can download the Code::Blocks IDE and a new copy of MinGW for around 70MB. Far (far) less if you choose to go without the IDE.

Though that is something of a side issue..
I'm much more concerned by your use of the words "Stdio.h lib function"
I can see two reasons just now that the compilation may fail:

1) You've not included the stdio.h file correctly (just #include stdio.h - don't forget add angled brackets, they can be difficult to represent in forums)
2) Your directory structure uses folders whose names are longer that 8 characters, your directory names contain spaces or the final file-path of any of your build diretories/include files/library files is longer than that allowed back when Borland's Turbo C(++) was modern.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900