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

#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;
}

Posted Date: 3/11/2013 5:57:55 AM | Location : United States







Related Discussions:- Example of switch case statement, Assignment Help, Ask Question on Example of switch case statement, Get Answer, Expert's Help, Example of switch case statement Discussions

Write discussion on Example of switch case statement
Your posts are moderated
Related Questions
Project Description: I would like to be building regarding a complex mobile application build as we require the signing of an NDA. My firm in based in Montreal Canada and we are

what is a variable

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.

It is a feature in C++ to reduce name collisions in the global name space. This namespace keyword assigns a separate name to a library that allows other libraries to use the simila

Define the Int Data Type of C Language? The int is used to define integer numbers. The Integers are whole numbers with a range of values supported by a particular machine and t

Write a recursive function recursiveMin that takes an integer array, a starting subscript and an ending subscript as arguments, and returns the smallest element in the array. The f

flow chart for prime or not

Run the following C++ program with and without preprocessor variable POSTFIX defined. #include using namespace std; extern "C" int atoi( const char *str );

Cross Platform Clinet app for a vpn Project Description: We want a cross platform client app for VPN. The app must have the subsequent options below: 1. Must be an open

find area uder the curve y=f(x) between x=a and x=b   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; in