Difference between revisions of "Conversions"

From Coder Merlin
(Created page with "thumb|Boeing, N780BA, B747-409(LCF) Dreamlifter == Prerequisites == * W1031 Positive Integers *...")
 
Line 10: Line 10:


== Type Casting ==
== Type Casting ==
 
When type casting, we consider an existing bit pattern as other than that originally declared.  For example, consider the following C program:
<syntaxhighlight lang="c" line>
#include <stdio.h>
int main(int argc, char *argv[]) {
  int c = 65;
  printf("The value is: %i", c);
  printf("The value is: %c", c);
  return 0;
}
</syntaxhighlight>
We declare an integer variable,


== Type Conversion ==
== Type Conversion ==

Revision as of 23:53, 7 November 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Boeing, N780BA, B747-409(LCF) Dreamlifter

Prerequisites[edit]

Introduction[edit]

In some cases we have a value of one type but want to use it in another context, as a different type. Depending on language, this may be referred to as "type conversion", "type casting", or "type coercion". Often, type casting refers to the mere re-interpretation of existing bits, while type conversion creates a new representation of data as a different type.

Type Casting[edit]

When type casting, we consider an existing bit pattern as other than that originally declared. For example, consider the following C program:

#include <stdio.h>
int main(int argc, char *argv[]) {
  int c = 65;
  printf("The value is: %i", c);
  printf("The value is: %c", c);
  return 0;
}

We declare an integer variable,

Type Conversion[edit]

Topic Headers[edit]

Key Concepts[edit]

Exercises[edit]

References[edit]