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


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
in a program for what purpose print f and scan f is used

What do you mean by a sequential access file? - When writing programs which store and retrieve data in a file, it's possible to designate that file into various forms. - A s

How to use HTTP Headers inside PHP? Write the statement through which it can be added? HTTP headers can be used in PHP by redirection that is written as: Headers can be

Static Data Members: A data member inside the class can construct as static data member.   There are few guidelines to be followed when declaring static data member.

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Default Arguments A default argument is a value that is automatically assigned to a formal variable, if the actual argument from the function call is omitted. e.g. void

#queWrite 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 c

You are to develop a Clinic System. 1. Identify and briefly explain the objects, classes, methods and attributes for the Clinic System. 2. Draw a use case diagram to represen

A function f is defined by the rule that f(n) = n if 0≤n≤3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n> 3. (a) Write a procedure that computes f by means of a recursive pro