#include <stdio.h>
int main() {
char myChar = 'A';
int myInt = myChar;
printf("myChar: %c\n", myChar);
printf("myInt: %d\n", myInt);
int myNewInt = 98;
char myNewChar = myNewInt;
printf("myNewInt: %d\n", myNewInt);
printf("myNewChar: %c\n", myNewChar);
return 0;
}
/*
CSE374 datatype demo by Diana Dai
Edited by Alex McKinney
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main(){
int anint;
float afloat;
char achar;
// some initial values:
printf("Set int to 374, float to 374.473, char to 'A'\n");
anint = 374;
afloat = 374.473;
achar = 'A'; // aka, ascii code 65
printf("int: %d, float: %f, char: %c\n", anint, afloat, achar);
printf("\n");
printf("Cast to int.\n");
printf("int: %d, float: %d, char: %d\n", anint, (int)afloat, (int)achar);
printf("\n");
printf("Cast to float.\n");
printf("int: %f, float: %f, char: %f\n", (float)anint, afloat, (float)achar);
printf("\n");
printf("Change int to 66, float to 66.76\n");
printf("Cast to char.\n");
anint=66;
afloat = 66.76;
printf("int: %c, float: %c, char: %c\n", (char)anint, (char)afloat, achar);
printf("\n");
printf("Change int to 321, float to 321.76 (overflow wraps around)\n");
printf("Cast to char.\n");
anint=321;
afloat = 321.76;
printf("int: %c, float: %c, char: %c\n", (char)anint, (char)afloat, achar);
printf("\n");
}