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
Receive 3 numbers and display them in ascending order from smallest to largest ed#

Define the Assignment Operators in c language? The assignment operators can be used to assign a value to the variable and is represented by equal to (=) sign. The Assignment ex

Ask question #write statement that assign random integer to the varaible n in the (100

Write three functions in C or C++: one that declares a large array statically, one that declares the same large array on the stack, and one that creates the same large array from t

Networking program development. 1.ARP protocol. 2.Switching HUB. 3.wireshark. 4.winpcap library. 5.C++ & MFC. 6.LAN evironment through switch and HUB(static ARP t

External Variables Different functions of the similar program can be written in different source files and can be compiled together. The scope of a global variable is not limit

Aim: To implement a program to swap two numbers using reference arguments. Code: void swap(int *a, int *b) {             int temp;             temp=*a;

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Introduction to C++ C++ was developed by Bjarne Stroustrup at Bell Laboratories in 1983. Originally, it was known as " C with class". C+ as an enhancement to the C language was

what is classes?