0

Can someone check if I got these correct please?? I'm pretty sure I missed almost half of these so I really need help on these. If someone can explain how to get an answer, that would be great.

a: 5
b: address of location of x (0x....)
c: address of value x (0x...)
d: address of value x (0x...)
e: 5
f: 3
g: 3
h: 6
i: 9
j: vals
k: address of vals + 1
l: address of ptrVals + 2
m: 0
n: 55
o: 55
p: 0

int x;
int *ptrX;

x = 5;

ptrX = &x;


cout << "a:" << x << endl;
cout << "b:" << &x << endl;   
cout << "c:" << ptrX << endl;
cout << "d:" << &ptrX << endl;
cout << "e:" << *ptrX << endl;

int vals[3];

*vals = 3;

vals[1] = *vals + 3;

*(vals+2) = 9;

cout << "f:" << vals << endl;
cout << "g:" << vals[0] << endl;
cout << "h:" << vals[1] << endl;
cout << "i:" << vals[2] << endl;


int *ptrVals;

ptrVals = vals;

cout << "j:" << ptrVals[0] << endl;

cout << "k:" << *(vals+1) << endl;

cout << "l:" << *(ptrVals+2) << endl;

int *ptr = NULL;

cout << "m:" << ptr << endl;

const int intRate = 55;   
const int *ptrRate;
ptrRate = &intRate;

cout << "n:" << intRate << endl;

*ptrRate = 66;

cout << "o:" << intRate << endl;
int * const ptrY = &x;

ptrY = &vals[0];
cout << "p:" << *ptrY << endl;
const int * const ptrZ = &intRate;

ptrZ = &vals[0];

*ptrZ = 7;

Edited by DS9596

5
Contributors
14
Replies
40
Views
1 Year
Discussion Span
Last Post by jacks009
Featured Replies
  • I've never heard of or used a fiddle before either. Just googled "C++ fiddle", picked the top result, then kept clicking my options for C++ and within 15 seconds, I got to a screen where I could copy and paste your code and compile. Showed the errors, commented the bad … Read More

  • > Oh, I went on it but it just shows me the errors..How does it take out bad lines or whatever? OK, so you DID find it, you were able to copy and paste the code in, got it to compile, and saw the errors. As far as "taking out … Read More

0

Your code is so incomplete that no one can try it. Example, line 56 and on do nothing. Why have those lines?

Tip? Go put it into some C++ online fiddle and see what happens. Then you can share the fiddle here.

0

Well, I didn't do write that code first of all, it's just supposed to be an example my professor put. Line 56 doesn't matter then. Forget about the stuff that doesn't work because that doesn't matter...Can you please just check the other stuff without compiling it??

Edited by DS9596

0

Yup, other lines give me errors in my head too. Same as JC above noted. I think you should re-read the assignment and go ahed with a working app. Again, use some C++ fiddle. If you never used a fiddle, just say so.

0

It's just a review example for an exam, not an assignment. I've never used C++ fiddle either.

0

I don't think it's supposed to be as complicated as we are making it though..

0

OK, you've never used a C++ fiddle. As a student you can now learn a few of the most powerful tools I've used over the years.

  1. Google. Google C++ fiddle and then
  2. Go to the fiddle and put in the code and try it out to see if it's right.

It's not complicated at all. You only need to do your search and work.

0

which one is it? when I click c++ it shows me to compileonline or gcc.gobalt??

Edited by DS9596

1

I've never heard of or used a fiddle before either. Just googled "C++ fiddle", picked the top result, then kept clicking my options for C++ and within 15 seconds, I got to a screen where I could copy and paste your code and compile. Showed the errors, commented the bad lines out, recompiled, then executed. Less than a minute total.

Votes + Comments
Let me show you the power of the dark fiddle. (Vader)
0

Oh, I went on it but it just shows me the errors..How does it take out bad lines or whatever?

Edited by DS9596

1

Oh, I went on it but it just shows me the errors..How does it take out bad lines or whatever?

OK, so you DID find it, you were able to copy and paste the code in, got it to compile, and saw the errors.

As far as "taking out bad lines or whatever", how would you do it if you had your computer/compiler/text editor/IDE right in front of you? You'd do one of three things.

  1. Fix the bad lines.
  2. Comment out the bad lines.
  3. Erase the bad lines.

Then you'd compile again. When you got no errors after compiling, you'd run it. Same here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.