Question

In: Computer Science

modify the program to cast vptr as a float and as a double build and run...

modify the program to cast vptr as a float and as a double

build and run your program

THIS IS THE PROGRAM CODE:

#include <stdio.h>

void main (void)

{

int intval = 255958283;

void *vptr = &intval;

printf ("The value at vptr as an int is %d\n", *((int *) vptr));

printf ("The value at vptr as a char is %d\n", *((char *) vptr));

}

Solutions

Expert Solution

Code:

#include <stdio.h>
void main (void)
{

int intval = 255958283;

void *vptr = &intval;

printf ("The value at vptr as an float is %f\n", *((float *) vptr));

printf ("The value at vptr as a double is %lf\n", *((double *) vptr));

}

Format specifier of float is %f just changed that in program

and format specifier of double is %lf

to type caste void to double just change the datatype to float

*((float *) vptr)

and same for double

*((double *) vptr)

Note:

here the output will not result 255958283.000000

because the type of intval is int and you are using float pointer(type casted) to access the value of intval.

But if the variable intval is float type and you are using float pointer then offcourse your output will result 255958283.000000

Screenshot:


Related Solutions

Java programming: Save the program as DeadlockExample.java   Run the program below.  Note whether deadlock occurs.  Then modify the...
Java programming: Save the program as DeadlockExample.java   Run the program below.  Note whether deadlock occurs.  Then modify the program to add two more threads: add a class C and a class D, and call them from main.  Does deadlock occur? import java.util.concurrent.locks.*; class A implements Runnable {             private Lock first, second;             public A(Lock first, Lock second) {                         this.first = first;                         this.second = second;             }             public void run() {                         try {                                     first.lock();                                     System.out.println("Thread A got first lock.");                                     // do something                                     try {                                                 Thread.sleep( ((int)(3*Math.random()))*1000);...
Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace...
Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace std; int main() { const int N=8; vector<int> nums(N); // User numbers int i=0; // Loop index cout << "\nEnter " << N << " numbers...\n"; for (i = 0; i < N; ++i) { cout << i+1 << ": "; cin >> nums.at(i); } // Convert negatives to 0 for (i = 0; i < N; ++i) { if (nums.at(i) < 0) {...
acos() Prototype double acos(double x); To find arc cosine of type int, float or long double,...
acos() Prototype double acos(double x); To find arc cosine of type int, float or long double, you can explicitly convert the type to double using cast operator. int x = 0; double result; result = acos(double(x)); int x = 0; double result; result = acos(double(x)); acos() Parameter The acos() function takes a single argument in the range of [-1, +1]. It's because the value of cosine is in the range of 1 and -1. Parameter Description double value Required. A...
I want c++ /c program to build a double linked list and find with a function...
I want c++ /c program to build a double linked list and find with a function the middle element and its position and the linked list must be inserted by the user aand note You should handle the both cases of whether the size of the list even or odd
def change_type(info: List[list]) -> None: """ Modify info to a float if and only if it...
def change_type(info: List[list]) -> None: """ Modify info to a float if and only if it represents a number that is not a whole number(a float), and convert info to an int if and only if it represents a whole number, keep everythingelse as a string. >>> i = [['apple', '888', 'School', '111.1']] >>> change_type(i) >>> i   [['apple', 888, 'School', '111.1']] Please help! Write as little code as possible! Please only use if statements, nested loop and lists to solve...
Modify program so that input comes in as command line arguments. Sample run: ./a.out W8 4...
Modify program so that input comes in as command line arguments. Sample run: ./a.out W8 4 ME 2 finish 2! Output: Consonants: WMfnsh 1) Name your program command_consonants.c. 2) If no command line arguments was provided, your program should print a usage message “Usage: ./a.out input #include<stdio.h> int main() { printf("Input: "); int i = 0; char ch; // array to store consonants char consonant[100]={""}; //do loop to take input do { ch = getchar(); //checks to see if consonants...
11. A cast iron flywheel is to be designed for a single cylinder double acting steam...
11. A cast iron flywheel is to be designed for a single cylinder double acting steam engine which delivers 150 kW at 80 r.p.m. The maximum fluctuation of energy per revolution is 10%. The total fluctuation of the speed is 4 per cent of the mean speed. If the mean diameter of the flywheel rim is 2.4 metres, determine the following : (a) Cross-sectional dimensions of the rim, assuming that the hub and spokes provide 5% of the rotational inertia...
Decimal value data types such as float and double represent the decimal number as an approximation....
Decimal value data types such as float and double represent the decimal number as an approximation. In other words, float or double arithmetic do not give exact answer but near approximation to the answer. As an example, run the following program and check its result: #include <iostream> using namespace std; int main() { float x= 0.1 * 7; if (x == 0.7) cout<< "TRUE. \n"; else cout<< "FALSE. \n"; return 0; } In some situations, we need our programs to...
Decimal value data types such as float and double represent the decimal number as an approximation....
Decimal value data types such as float and double represent the decimal number as an approximation. In other words, float or double arithmetic do not give exact answer but near approximation to the answer. As an example, run the following program and check its result: #include <iostream> using namespace std; int main() { float x= 0.1 * 7; if (x == 0.7) cout<< "TRUE. \n"; else cout<< "FALSE. \n"; return 0; } In some situations, we need our programs to...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year,...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) -Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating def list(movie_list): if len(movie_list) == 0: print("There are no movies in the list.\n") return else: i = 1 for row in movie_list: print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")") i += 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT