Concept explainers
Explanation of Solution
Corresponding modified code for “show_bytes”:
#include <stdio.h>
//Define variable "byte_pointer" in char datatype.
typedef unsigned char* byte_pointer;
//Function definition for show_bytes.
void show_bytes(byte_pointer start, size_t len)
{
//Declare variable "i" in int data type.
int i;
/* "For" loop to determine byte representation in hexadecimal */
for (i = 0; i < len; i++)
//Display each bytes in "2" digits hexadecimal value.
printf(" %.2x", start[i]);
printf("\n");
}
//Function to determine byte for "int" data type value.
void show_int(int x)
{
//Call show_bytes function with integer value.
show_bytes((byte_pointer) &x, sizeof(int));
}
//Function to determine byte for "float" data type value.
void show_float(float x)
{
//Call show_bytes function float value.
show_bytes((byte_pointer) &x, sizeof(float));
}
//Function to determine byte for "pointer" value.
void show_pointer(void *x)
{
//Call show_bytes function with pointer value.
show_bytes((byte_pointer) &x, sizeof(void *));
}
//Function to determine byte for "short" data type value.
void show_short(short x)
{
//Call show_bytes function with short int value.
show_bytes((byte_pointer) &x, sizeof(short));
}
//Function to determine byte for "long" data type value.
void show_long(long x)
{
//Call show_bytes function with long value.
show_bytes((byte_pointer) &x, sizeof(long));
}
//Function to determine byte for "double" data type value.
void show_double(double x)
{
//Call show_bytes function with double value.
show_bytes((byte_pointer) &x, sizeof(double));
}
//Test all show bytes.
void test_show_bytes(int val)
{
//Define variables.
int ival = val;
float fval = (float) ival;
int *pval = &ival;
//Call function.
show_int(ival);
show_float(fval);
show_pointer(pval);
//Define variables.
short sval = (short) ival;
long lval = (long) ival;
double dval = (double) ival;
//Call function.
show_short(sval);
show_long(lval);
show_double(dval);
}
//Main function.
int main(int argc, char* argv[])
{
//Define the sample value.
int sampleValue = 1024;
//Call test_show_bytes function.
test_show_bytes(sampleValue);
return 0;
}
The given program is used to display the byte representation of different program objects by using casting...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
EBK COMPUTER SYSTEMS
- Write answer in C++ language. Take 5 integer inputs from user and store them in an array. Now, copy all the elements in another array but in reverse order.arrow_forwardWrite a C program that uses arrays and functions to implement a calculator for twooperands. Your calculator must have five principal operations, addition ( ), subtraction ( ),division ( ), multiplication ( ), and power ( ). In the beginning of the program, show the menuof operators to the user. When the user selects one of the operators, your program gets the valuesfor operand 1 and operand 2 from the user and saves them into an array. Then pass the array to thesuitable function to calculate the result. The operating functions must return the value to the mainprogram. The calculation stops when the user press “x”. Use a global variable to save the result oflast operation. Anytime that the user types “M”, the program shows the result of last operation.hint: Each mathematic operation must be a separate function. Your main program calls those functions.arrow_forwardWrite this program in C programming language. Also provide a screenshot that it is working.Here is the question:Write a program that determines the three largest elements among inputed numbers.arrow_forward
- Create a class reversstring in c++andWrite a function called reversit () that reverses a C-string (an array of char). Use a forloop that swaps the first and last characters, then the second and next-to-last characters, and so on. The string should be passed to reversit () as an argument. Write a program to exercise reversit (). The program should get a string from the user, call reversit (), and print out the result.arrow_forwardWrite in c++ ....arrow_forwardIn c++ , perform data searching using linear and binary search. ( Drop code in words , explain the code and drop the screenshot of output as well )arrow_forward
- Implement the charAt function of Java in C++. Function takes two argument i.e. string and integer i and return the character at index i in the string. Function returns NULL if Integer i is not in valid range.arrow_forwardHi! I need some help writing some code in C language (NOT C++/Java/Python!). How can I merge two different sentences (defined by user input - stored in arrays?) with alternating letters, print it, and then print it backwards? I would also like to remove any gaps or spaces before the sentences are merged. For example: Sentence 1 = I like cake Sentence 2 = I like donuts Merged sentences = IIlliikkeecdaokneuts Backwards merged sentences = stuenkoadceekkiillIIarrow_forwardWrite a program in C languagearrow_forward
- Please use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 2. Write a recursive function that reads words from the standard input stream and displays them in reverse order on the standard output stream. For example, if the input was: here comes the sun, the output would be: sun the comes here. Hint: Read individual words until the end of a sentence is reached. You can determine the end of the sentence any way you like. Some suggestions include (a) checking the last character of a word for a sentence terminator (. ? ! ) (b) Using a keyword such as 'quit' to indicate the end of input. (c) Using the eof method of the cin object. (ctrl Z for windows or ctrl D for others can be used to force an end of file from the keyboard.)arrow_forwardIn c++ , perform data sorting using quick sorting. ( Drop code in words , explain the code and drop the screenshot of output as well )arrow_forwardFOR C++ In this assignment, we are going to implement a couple of sorting algorithms and test their performances. So the idea is as follows: You should write a program to sort an array. For this purpose, you will implement two sorting algorithms: Insertion Sort and Merge Sort. For each algorithm, you are supposed to have a counter and count how many times a comparison is made to sort the array. Once this logic is implemented, create integer arrays of 1000 and 10000 elements with random values inside (you can implement a random number generator for this purpose and randomize their elements). Then go ahead and run your application. The output should show us how many comparisons it made for each algorithm for 1000 and 10000 elements. //header file#include<iostream>#include<time.h>//using namespaceusing namespace std; // Insertion sort sorting function it will take array and its size an argumentvoid insertionSort(int nums[], int m, int& comparisonsCount){ int j, val,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education