473,672 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please solve my confussion

HP

Hi All
i have confussion regarding given problem
please help me out
4. What happens with the following program:
void main(){
myclass* pmc = new myclass;
pmc = 0;
delete pmc;}

5. What is the difference between the statements
short* p = new short(500);
And
short* p = new short[500];
6. How would you deallocate the memory for :
short* p = new short(500);
And
short* p = new short[500];

7. How is an array of 10 pointers to int allocated from heap

Oct 25 '05 #1
14 1646
HP
is there no body who know these thing

Oct 25 '05 #2
On 24 Oct 2005 22:56:19 -0700, "HP" <hi********@red iffmail.com> wrote:

Hi All
i have confussion regarding given problem
please help me out
4. What happens with the following program:
void main(){
myclass* pmc = new myclass;
pmc = 0;
delete pmc;}

5. What is the difference between the statements
short* p = new short(500);
And
short* p = new short[500];
6. How would you deallocate the memory for :
short* p = new short(500);
And
short* p = new short[500];

7. How is an array of 10 pointers to int allocated from heap

I think this is homework. Try looking to agood C book, i.e.K&R, and
try to work the answers from it.
Oct 25 '05 #3
HP wrote:

is there no body who know these thing


Yes, there is.
But honestly, the problem is:
In another thread you described what you need to do, what your
assignment asks for. Except of one or two things, these assignment
isn't difficult and I would expect a programmer to code 90% of it
with easy. On the other hand, this assignment is extremely difficult
for a non programmer and your questions show, that you need to learn
a lot of things before you can even think about calling yourself
in a programmer. SO i guess what most of us fear is simply: To write
this application for you.

Otherwise:
Get yourself a book and start studying the basics. Programming, especially
C++ programming isn't something you can learn in a day or 2. Reserve a few
month for learning the basics, before you can even think about takling
your assignment problem.

Good luck.

--
Karl Heinz Buchegger
kb******@gascad .at
Oct 25 '05 #4
HP
Hi Zara
Its not a hoework, i m realy confuse in my project work.
i m not able to get answer of this
please help me

Oct 25 '05 #5
HP wrote:

Hi All
i have confussion regarding given problem
please help me out

4. What happens with the following program:
void main(){
myclass* pmc = new myclass;
pmc = 0;
delete pmc;}
you got a memory leak
(and btw: the return type of main is always int)

5. What is the difference between the statements
short* p = new short(500);
And
short* p = new short[500];

the first creates *one* int and intializes it with 500
the second creates an (unniitialzed) array of 500 int
6. How would you deallocate the memory for :
short* p = new short(500);
And
short* p = new short[500];
delete p;
delete [] p;

7. How is an array of 10 pointers to int allocated from heap


int** p = new int* [10];
Get a book on C++ and practice, practice, practice

BTW: if you need all of the above extensively, you are barking
up the wrong tree. Use std::vector, std::list, std::map or whatever
other container fits your bill. That's the C++ way to handle most
of the data structure problems in a program.

--
Karl Heinz Buchegger
kb******@gascad .at
Oct 25 '05 #6
HP
Thankx ZARA

Oct 25 '05 #7
"HP" <hi********@red iffmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

Hi All
i have confussion regarding given problem
please help me out
If this is your homework (as I strongly suspect), then you're losing out by
not doing it yourself because you probably still won't understand it
afterwards. But since I'm feeling kind...

Stu

P.S. Get a book! :) Take a look at
http://www.accu.org/bookreviews/publ...nner_s_c__.htm to
give you some ideas about what's worth getting.
4. What happens with the following program:
void main(){
myclass* pmc = new myclass;
pmc = 0;
delete pmc;}
It doesn't compile (main always returns int, and myclass isn't declared).
Were the program, on the other hand:

class myclass
{
// something useful here
};

int main()
{
myclass *pmc = new myclass;
pmc = 0;
delete pmc;
return 0; // (ok, you could leave this line out as it happens...)
}

Then it would cause a memory leak, because you allocate a myclass object on
the heap, overwrite the pointer to it (by setting it to 0) and then try and
delete 0, which is a no-op. The object you allocated on the heap is still in
existence, you just don't have a pointer to it any more.
5. What is the difference between the statements
short* p = new short(500);
And
short* p = new short[500];
The first one allocates a single short on the heap, with value 500, and
stores its address in p.
The second one allocates an array of 500 shorts on the heap, and stores the
address of the first element of the array in p.
6. How would you deallocate the memory for :
short* p = new short(500);
And
short* p = new short[500];
delete p; for the first one
delete [] p; for the second one
7. How is an array of 10 pointers to int allocated from heap


int **p = new int*[10];
Oct 25 '05 #8

"Zara" <no***********@ terra.es> wrote in message
news:5l******** *************** *********@4ax.c om...
On 24 Oct 2005 22:56:19 -0700, "HP" <hi********@red iffmail.com> wrote:

Hi All
i have confussion regarding given problem
please help me out
4. What happens with the following program:
void main(){
myclass* pmc = new myclass;
pmc = 0;
delete pmc;}

5. What is the difference between the statements
short* p = new short(500);
And
short* p = new short[500];
6. How would you deallocate the memory for :
short* p = new short(500);
And
short* p = new short[500];

7. How is an array of 10 pointers to int allocated from heap

I think this is homework. Try looking to agood C book, i.e.K&R, and
try to work the answers from it.


It seems that you might need a book or two as well. :-)
Why do you recommend a C book for learning C++?

-Mike
Oct 25 '05 #9

Stuart Golodetz wrote:
"HP" <hi********@red iffmail.com> wrote in message
If this is your homework (as I strongly suspect), then you're losing out by
not doing it yourself because you probably still won't understand it
afterwards. But since I'm feeling kind...


"When a slackard asks comp.lang.c++ to do their homework for them,
answering their question is the worst thing for them. Please don't do
it!"

http://www.parashift.com/c++-faq-lit...t.html#faq-5.3

Oct 25 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1655
by: Mat | last post by:
I am developping multi-user windows application. i use Access database. user edit, add and delete data from database. Request: when an item is deleted ,added or modified by an user, all others user in the network which has application running should automatically see the change. in case of remove action, the item should disappear from the listview.
5
2236
by: CoreyWhite | last post by:
It is possible to use martingale probability theory to beat some games of chance. In a fair game of coin toss, where the odds reach an equilibrium of 50/50 chain reactions do occur. This can be explained using martingale probability theory, but in simpler terms it only shows an example of how order emerges out of chaos. Example: One player has 3 pennies, and another player has only 1 penny. A fair coin is tossed every round to determine...
5
2579
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
1
1695
by: shapper | last post by:
Hello, For the past hours I have been trying to solve a problem which is driving me crazy. I have to different codes where the problem to solve is the same: CODE 1 (Transforms a XML document using a XSL file): Function Trans()
14
3455
by: rashmidutt | last post by:
hello sir i am making project on vb.net language..and project is on hospital management..its major project..and too many fields are present in its data base..i was connecting data base in forms but there is coming error..SIR PLEASE SORT OUT ERROR FROM MY COADING..what can i do to solve this error please give me sugession or if you can send me coading for adding information from form.than i will be thankfull to u..i have written all fields which...
2
2373
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created table login with fields username(varchar(50)), password(varchar(50)), firstname(varchar(50)), lastname(varchar(50)). U had to display username , first name, last name in default.aspx page after login. One more condition is that, if user fails login...
6
2188
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
0
2729
by: xwebmaster | last post by:
Hi Please help me solving this query.. I have 3 tables.. comm_propDB ID | User_ID | mls_num -----|---------------|--------------------- 2 | 2 | 5004 3 | 2 | 8920 8 | 2 | 5540
0
8503
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8419
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7472
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6254
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4239
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2092
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1836
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.