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
If we take the input image and smooth it with a Gaussian of a significant size before computing the Canny edges does the number of edges change, and do the locations of these edges

Program to Open a file in C++: int main() {                  char ch;                  ifstream f1 ("OLDFILE.TXT");                  ofstream f2 ("NEWFILE.TXT");

Problem 1 What is the difference between function declaration and function definition? 2 Write a recursive function to find sum of even numbers from 2 to 10. 3 List some


write aprogram in c++ to overload +,-,=,++ operator using unary and friend function in a single program

What is Namespace and Explicit container Namespace - Namespaces are used to group entities such as objects, classes and functions under a name. Explicit container.

how we write decision tables, flowcharts,pseudocode,and algorithm in result management system

Develop a Motion sensor in Altera control Project Description: I want a project written in c using Altera eclipse development tool, that controls a motion sensor ( SRF05 ) fr

In this assignment the main has been written for you in the file phone_book_main.cpp. You will also notice that a class called Person has been declared as having several prototypes

(a) Write a fragment of code that declares a variable colSp of type ColourSpot, and then moves it to the point (3, -4), and sets its colour to Green. (b) A function QU8 is speci