[Courses] C Programming For Absolute Beginners, Lesson 2: Fun With Printf, Scanf, Puts, and Variables
Sachin Divekar
ssd532 at gmail.com
Tue Feb 21 18:40:25 UTC 2012
> /* addition; an example of adding and displaying user input */
>
> #include <stdio.h>
>
> int main()
> {
> int a, b, c;
>
> puts( "Please enter any number up to three digits: " );
> scanf( "%d", &a );
> puts( "Please enter another number up to three digits: " );
> scanf( "%d", &b );
> c = a + b;
> printf("%d + %d = %d\n", a, b, c);
>
> return 0;
> }
>
> When you run it it looks like this:
>
> $ addition
> Please enter any number up to three digits:
> 34
> Please enter another number up to three digits:
> 567
> 34 + 567 = 601
>
Hi,
I am really enjoying discussions on this course's mailing list.
Now towards the question.
I tried a very large input to addition program. Following was the result.
==========================================
sachin at sachin-ThinkPad-T420:~/projects/C$ ./addition
Please enter any number up to three digits:
1111111111111111111111111
Please enter another number up to three digits:
1111111111111111111111111111111111111111111111
-1 + -1 = -2
===========================================
A quick reading on Wikipedia about C data type "int" says,
"basic signed integer type. At least 16 bits in size."
So, what exactly "16 bits in size" means? I know 1 bit is either state
1 or 0. But how this(bits) determines size of number?
Thanks.
--
Regards,
Sachin
More information about the Courses
mailing list