SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 23 Oct 2017 My Price 9.00

Why is the last byte shown first?

Question: At line 45, we are printing only one byte of the 32-bit variable, myInt. myInt as defined to be 0x11223344. Why is the last byte shown first?

 

CODE PROVIDED BELOW

 

/* 

 * Module name: debugging_demo_main.c

 * Author: The teacher

 * Date: August 22, 2017, 4:13 PM

 * Description: Demonstration of debugging (there is a bug in the code).

 */

 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

/* Description: main function

 * Receives: Nothing

 * Returns: Exit status

 * Requires: Nothing

 */

int main(void) {

  char *myString = "This is my string!";

  char *buffer;

  int myInt = 0x11223344;

  int strSize;

  int value;

 

  // Get the number of characters in the string

  strSize = strlen(myString);

  printf("The size of myString is %d.n", strSize);

  // Allocate memory for buffer, make it a bit larger than needed

  buffer = malloc(strlen(myString) + 10);

  // Fill the buffer with known values

  value = 0x41;

  for (int i = 0; i < (strlen(myString) + 10); i++) {

    buffer[i] = value++; // Copy value, then increment value

  }

  // Now copy myString

  strncpy(buffer, myString, strSize);

  // Print results

  printf("Original string: %sn", myString);

  printf("Copy of string: %sn", buffer);

  // Print the first byte of myInt

  printf("The first byte of myInt = %hhxn", myInt);

  // Free up the memory we allocated

  free(buffer);

  return (EXIT_SUCCESS);

}

Answers

(5)
Status NEW Posted 23 Oct 2017 06:10 AM My Price 9.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)