C++. What is happening in this code?
I'm having a bit of difficulty understanding some lines of code due to pointers. Please refer to the comments and correct me on what is going on in the code. Thank you.
Practice code:
int ted = 25;
//int andy;
cout << ted << endl; //Prints 25
cout << endl;
int*andy = &ted;
cout << ted << endl; //Prints 25
cout << endl;
cout << &ted << endl; //Prints address of
ted
cout << endl;
cout << andy << endl; //Prints same address
cout << endl;
cout << *andy << endl; //Prints 25
cout << endl;
cout << &andy << endl; //Prints the address of
int*andy
cout << endl;
cout << ted << endl;
cout << endl;
//cout << *ted << endl; //Question: Why won't this
run?
//cout << endl;
int* fred = andy; //Question: What is happening here?
cout << andy << endl;
cout << endl;
cout << fred << endl; //Question: What is happening
here?
cout << endl;
cout << *fred << endl; //Prints 25
cout << endl;
cout << &fred << endl; //Question: What is
happening here?
cout << endl;
cout << &andy << endl; //Question: What is
happening here?
cout << endl;
cout << *andy << endl; //Prints 25
cout << endl;
******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per HomeworkLib expert answering guidelines,Experts are supposed to
answer only certain number of questions/sub-parts in a post.Please
raise the remaining as a new question as per HomeworkLib
guidelines.
******************************************************************************************
please do reachout to me if you need more explanation, as I can
understand that the concept of pointers take some time to
understand :)
* is read as value at the address of
& gives the address of the variable
so *Fred means the value at the address of Fred, means it will take the value of Fred goes to the address where the address value = fred value and returns the value at that address
//cout << *ted << endl; //Question: Why won't this
run?
//cout << endl;
// because ted is a variable and * means value at the
// address of red so which means you are finding the
// value at the address of 25, since we dont know
// what is there at the address of 25 compiler might give
//error or some random value

C++. What is happening in this code? I'm having a bit of difficulty understanding some lines...
Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...
C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble with is in bold. -------------------------------------------------------------------------------------------------driverProgram.cpp #include #include #include #include #include "quickSort.cpp" using namespace std; int main() { const int MIN_SIZE = 4; //Array size const int SIZE = 25; int theArray[SIZE] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25}; cout << "List of 25 items: ";...
So I'm not sure what I'm trying to do here. I don't understand how *adr works, I guess it's a pointer to the struct Address. How do I complete this function? And how would I have it just return the zip code or one element if I wanted to? I have two structs: struct Address { int number; // street number string street; // street Name string city; // city short zip; // zip code ...
Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your name and the date. Describe the purpose of the code. Also, list each pointer and describe how it is used to enable the selection sort for the linked list structure. */ /* Insert code as described by the comments. */ /* Add comments to each line of code that uses a pointer, describing how it is being used. */ #include <iostream> using namespace std;...
Can someone please explain to me this? I'm having a
hard time understanding it. thank you
2:31 $32% X 324 325 14) Given the following function definition: void calc (int a, int& b) intc; C = a + 2; a = a* 3; b = c + a; What is the output of the following code fragment that invokes calc? int x = 1; int y = 2; int z = 3; calc(x,y); cout << x <<""<< y «""<< Z...
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...
Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...
Hey I'm trying to convert this C code into ARMv8 however I'm having severe difficulty while doing it. This is just for personal practice to develop my skills. Thank you! // Code starts here // This is a C language code below #define FALSE 0 #define TRUE 1 struct coord { int x, y; }; struct size { int width, length; }; struct pyramid { struct coord center; struct size base; int height; int volume; }; struct pyramid newPyramid(int width,...
I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below. If you could leave comments pointing out where pointers are used it would be much appreciated! ----------------------------------------------------------------------------------------------------------------------------------- Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a...
I have been looking over and interpreting some sample code and am having some trouble understanding what is going on with a bit of slicing syntax. For some context I am working on a computational program that uses method of finite differences approximating temperatures over a square region. Here is some of the code: maxIter = 500 lenX = lenY = 20 delta = 1 Ttop = 100 Tbottom = 0 Tleft = 0 Tright = 0 Tguess = 30...