I came across the following unexpected behaviour while working on pset2 does any body have any idea why this is happening in the following code, at the 9th line.
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
int main(int argc, string argv[])
{
char added1 = 'r' + (tolower('Z') - 'a') ;
//shouldn't what added1 holds be the same as the one printf function
//calculates be the same but as it can be seen by runing the program
//they aren't why?
printf("added1:%i, added2:%i\n" ,added1,'r' + (tolower('Z') - 'a'));
}
here is the output i get when i run my program:
added1:-117, added2:139
also doing this will give the same effect as the printf addition gives
int plainTextInt = 'r' ;
int keyInt = (tolower('z') - 'a') ;
int added3 = plainTextInt + keyInt;
printf("added3:%i\n" ,added3);
the out put for this one is
added3:139//the same as the added2 value (the one from the printf function)