Example of switch case statement, C/C++ Programming

Assignment Help:

#include
#include
#include

void* memorycopy (void *des, const void *src, size_t count)
{

  size_t n = (count + 7) / 8;
  char* destination = (char *) des;
  char* source = (char *) src;

  switch (count % 8)
  {
      case 0:  do{  *destination++ = *source++;
      case 7:  *destination++ = *source++;
      case 6:  *destination++ = *source++;
      case 5:  *destination++ = *source++;
      case 4:  *destination++ = *source++;
      case 3:  *destination++ = *source++;
      case 2:  *destination++ = *source++;
      case 1:  *destination++ = *source++;

    } while (--n > 0);
  }

  return des;
}

void tworegistervarswap (int *x, int *y)
{
  if (x != y)
  {
    *x = *x ^ *y;
    *y = *x ^ *y;
    *x = *x ^ *y;
  }
}

int bigintegeraverage (int x, int y)
{
  return (x & y) + ((x ^ y) >> 1);
}

int main (void)
{
  char *testArray = "This is a test.";
  char buffer[50];
  int x = 10;
  int y = 20;
  int m = 2000000000;
  int n = 1000000000;
 
  printf ("\nmemorycopy test before: %s", testArray);
  memorycopy (buffer, testArray, strlen(testArray) + 1);
  printf ("\nmemorycopy test after: %s", buffer);
  printf ("\n");

  printf ("\ntworegistervarswap test before: %d %d", x, y);
  tworegistervarswap (&x, &y);
  printf ("\ntworegistervarswap test after: %d %d", x, y);
  printf ("\n");

  printf ("\nbigintegeraverage regular code test: %d ", (m + n) / 2);
  printf ("\nbigintegeraverage function test: %d", bigintegeraverage (m, n) );
  printf ("\n");

  return 0;
}


Related Discussions:- Example of switch case statement

Data Handling in computers, though the ascii is called 7-bit code. why do w...

though the ascii is called 7-bit code. why do we use 8-bits to represent a character?

Define the float data type of c language, Define the Float Data Type of c L...

Define the Float Data Type of c Language? The float is used to define floating point numbers. The Floating point numbers are stored in 32 bits with 6 digits of precision. Eg

Online tutor, Given an char variable last that has been initialized to a lo...

Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combinations of two letters in the range ''a'' through last. Th

Write a program to calculate the total resistance, Write a program to calcu...

Write a program to calculate the total resistance of a series or parallel circuit. The maximum number of resistors is two.   We need to decide whether the user wants the to

AREA UNDER CURVE, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Explain passing and returning objects, Passing and Returning Objects Ob...

Passing and Returning Objects Objects can be passed to a function and returned back just like normal variables. When an object is passed by content, the compiler makes another

Help, Deliverables: you are required to upload your c code in the assignmen...

Deliverables: you are required to upload your c code in the assignment dropbox set in Moodle. You are supposed to work with Linux gcc compiler and pico editor for compiling via the

Explain about the constants in c language, Explain about the Constants in c...

Explain about the Constants in c language? The Constants in C refer to fixed values that don't change during the execution of a program. C has four fundamental types of constan

How the operations are performed in a single linked list, Question: (a)...

Question: (a) Explain a linked list. (b) Describe the three different types of linked list with the help of diagrams. (c) Give two advantages and two disadvantages

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd