473,832 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Your C++ Homework

I used this site for a c++ homework assignment that my teacher left me no
clue on how to do it. http://www.betterteachers.com. Check it out.

Fred
Jul 22 '05
31 2234

"Joe Van Dyk" <jo*******@no.s pam.gmail.com> wrote in message
news:2004102716 345516807%joeva ndyk@nospamgmai lcom...
On 2004-10-27 02:17:09 -0700, "Gernot Frisch" <Me@Privacy.net > said:

So, if I have a pointer to an int that's unitialized, how do I tell it to
point at a given int?


Two ways:

Point it at an existing variable:

int* p; // uninitialized
....
int a = 6; // stores 6 in variable a
....
p = &a; // now, p points to a, so *p == 6
or,

Create its own memory to point at, and assign a value to that

int* p; // uninitialized
....
p = new int; // create new storage for p to point to
....
*p = 9; // stores 9 in memory set aside for *p
....
delete p; // don't forget to delete when you new!

-Howard

(P.S., you could also set the value of *p in the new statement itself, with
p = new int(9);)
Jul 22 '05 #31
[snips]

On Wed, 27 Oct 2004 23:35:04 +0000, Joe Van Dyk wrote:
So, if I have a pointer to an int that's unitialized, how do I tell it
to point at a given int?


Assign it.

int *p; // uninitialized
int x;

*p = 3; // invalid, p hasn't been pointed at anything
p = &x; // perfectly good, points p at x
if ( *p ) // bad again, as x (aka *p) has no defined value
x = 3; // perfectly good
if (*p) // okay now, as x is initialized
Jul 22 '05 #32

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

Similar topics

0
2220
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to python-help, to point out a few resources that can help with answering your own questions, or improve the chances of getting a useful answer from the helpers. The most comprehensive overview of python.org help resources is at ...
0
1806
by: | last post by:
I have this question for homework in an intro perl class, I was hoping for some quick help on this please...here is the question Using the Perl programming language, please prepare the following script: Description Given a table 'mailer' that has a column: emailaddr varchar(255) Create a new table to hold a count of email addresses by their domain name limited to those domains that have at least 100 addresses in the list and add a...
2
2283
by: N3TB1N | last post by:
Let me try again. I could use some help with this assignment, even though my teacher does not grade assignments.but because I need to know this stuff for a test very soon, but haven't been in class for awhile and don't know what I'm doing. I have included my (probably wrong) answers for the first few questions. It would be great if someone could tell me what is missing or what I need to work on at least just for the first few. I...
19
1902
by: Guy | last post by:
If you are tired of trying to timely backup your project you should read this message. Relative Reversion is a new innovative product that will not only schedule your backup sessions incrementally, but it will also manage the number of backup snapshots that you want to keep on your storage media. Older backup snapshots are cleared automatically per your specifications, which makes room for newer backup snapshots to be stored. All the...
8
1535
by: jane | last post by:
like, my homework is due at 4:30 pm central time Nov 19, and this stupid professor has no respect for my need to use my time elsewhere. He thinks that if the braces are off, then there's something wrong, but I got my braces off while dating Billy 2 years ago, and I was hotter, so I could start dating Chad on the hockey team. It's so nice to have a friendly place to talk about things:-) Anyways this professor wants me to use c to hurl a...
6
1747
by: wandafoda | last post by:
Sorry guys....another homework question and if you don't wanna help out..i understand. just to say..im' a chemical engineer and we are required at will to do whatever...thast why i have to take C++ and would like to also understand what im' doing.....to further my career.. i'll include the program after the description So my teacher gave the class an algorithm we have to manipulate......its a struct and i understand what is going on in...
6
1222
by: Nep Tune | last post by:
It goes like the following: Use AdventureWorks database and HumanResources.Department table. Create a stored procedure called spDepartmentAddUpdate. This procedure accepts two parameters: Name, and GroupName. The data types are VarChar(50), and VarChar(50) respectively. Define logic in this procedure to check for an existing Department record with the same Name. If the department record exists, update the GroupName and ModifiedDate....
103
6891
by: Tom | last post by:
How do we get out of the browser infinite loop quicksand when we navigate to web pages designed to lock us in and force us to hit the "pay me" button (whatever they want to force you to do)? These are just a sample of nasty quicksand web pages I've run into which lock your browser into a loop and won't let you get out until you hit the "install" or "run" or "OK" button... (whatever it is they want you to do). http://www.spywareiso.com...
0
9795
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
9642
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
10781
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...
1
10541
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9320
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...
0
5624
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...
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.