Run the C program below and complete the table showing all the variables. Add printf function calls to obtain the addresses and values of all 13 variables. (Count the array (ca) as 3 variable/values and also include argc and argv in the table). The table must show the Address, Name, Datatype, Scope, and Value of each variable on the stack. (Hint: use the sizeof function to double check your addresses.) Explain how different the actual memory allocations are from what you practiced by hand in the classes. (Don't just say like "it is totally different from what I thought." "It is randomly allocated." or any abstract impression.) int main(int argc, char* argv[]) { int num1, num2 = 13; char c = 'H'; float score1 = 12.5; char ca[3] = "Hi"; dummy(num2, c, ca, score1); /* pause here */ return 0; } void dummy(int x, char y, char * z, float w) { x++; y++; w = w + 2.3; }
C program with printf statements added
#include<stdio.h>
int main(int argc, char* argv[])
{
int num1, num2 = 13;
char c = 'H';
float score1 = 12.5;
char ca[3] = "Hi";
dummy(num2, c, ca, score1);
//printing all variable values and addresses
printf("num1=%d, address of num1=%d \n",num1,&num1);
//num1
printf("num2=%d, address of num2=%d \n",num2,&num2);
//num2
printf("c=%c, address of c=%d \n",c,&c); //c
printf("score1=%f, address of score1=%d \n",score1,&score1);
//score1
printf("ca[0]=%c, address of ca[0]=%d \n",ca[0],&ca[0]);
//ca[0]
printf("ca[1]=%c, address of ca[1]=%d \n",ca[1],&ca[1]);
//ca[1]
printf("ca[2]=%c, address of ca[2]=%d \n",ca[2],&ca[2]);
//ca[2]
return 0;
}
void dummy(int x, char y, char * z, float w)
{
x++;
y++;
w = w + 2.3;
//printing values of all variables and their addresses
printf("x=%d, address of x=%d \n",x,&x); //x
printf("y=%c, address of y=%d \n",y,&y); //y
printf("w=%f, address of w=%d \n",w,&w); //w
printf("z[0]=%c, address of z[0]=%d \n",z[0],&z[0]);
//z[0]
printf("z[1]=%c, address of z[1]=%d \n",z[1],&z[1]);
//z[1]
printf("z[2]=%c, address of z[2]=%d \n",z[2],&z[2]);
//z[2]
}
The addresses of x and num2 are different because num2 is passed by value(not passed by reference). Similarly, addresses of y & c and w & score1 are different. Also, the changes made in the function dummy() are not reflected in the variables in main beacuse the changes are made in the copies of these variables and not the actual variables.The addresses of ca and z are same because arrays are always passed by reference.
variable | datatype | address | value | scope |
num1 | int | 2686748 | 2 | main |
num2 | int | 2686744 | 13 | main |
c | char | 2686743 | H | main |
score1 | float | 2686736 | 12.5 | main |
ca[0] | char | 2686733 | H | main |
ca[1] | char | 2686734 | i | main |
ca[2] | char | 2686735 | NULL | main |
x | int | 2686788 | 14 | dummy |
y | char | 2686768 | I | dummy |
w | float | 2686700 | 2.5 | dummy |
z[0] | char | 2686733 | H | dummy |
z[1] | char | 2686734 | i | dummy |
z[2] | char | 2686735 | NULL | dummy |
Run the C program below and complete the table showing all the variables. Add printf function...
answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...
Learn the example C program in Folio consisting of three files (a.c, a.h, main.c) and complete this exercise. You need to understand function, pointer and the selection sort algorithm. Write a C program that consists of three files mysort.h, mysort.c and myMain.c. Below is the mysort.h prototype #include <stdlib.h> #include <stdio.h> void generateNums(int *myarr, int len); void sortNums(int *myarr, int len); mysort.h must contain only the function declarations (prototypes) listed above generateNums function should generate len random integers in the...
Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...
How do I do this C++ in a Unix Environment assignment Given dot1m.c 1. The program (dot1m.c) uses mutex to lock and unlock the shared resource (dotstr.sum) for access control as shown below. pthread_mutex_lock (&mutexsum); dotstr.sum += mysum; printf("Thread %ld did %d to %d: mysum=%f global sum=%f\n", offset,start,end,mysum,dotstr.sum); pthread_mutex_unlock (&mutexsum); 2. Modify dot1m.c program to use reader-writer lock (instead of mutex). Replace the codes (for mutex) by the codes (for reader-writer lock). To initialize reader-writer lock, pthread_rwlock_initializer. At the end,...
Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....
These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....