Example solution

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* ELEC1620 Lab 2 Task 7
00002 
00003 Overflow
00004 
00005 (c) Dr Craig A. Evans, Feb 2017
00006 
00007 */
00008 
00009 #include "mbed.h"
00010 
00011 int main()
00012 {
00013     // use the 'signed' keyword when declaring the variable
00014     signed char c = 127;
00015     printf("c has a value of %d\n",c);
00016 
00017     printf("We'll now incrememt it by 1\n");
00018     c++; // increment operator, could also do c = c + 1;
00019 
00020     printf("Now it has a value of %d\n",c);
00021     printf("Wow! This is overflow in action!\n");
00022     printf("The number has gone out of the range of an 8-bit value.\n");
00023 
00024 }