Lesson 4: Casting data types

E-mail this post

All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...

Someone's going to assume I'm workaholic since it has passed less then twelve hours since my last programming post, but what the heck, I assume you are willing to learn since you're here - so here's fourth lesson for all of you. This lesson is about transformation (casting) of integers and real data types, and explanations why this job is necessary in C language for compiler to understand the syntax. It's a short one, but with compressed value.

DECLARATION OF INTEGER (int) TYPE:

CASTING DATA TYPES:

Result type of arithmetic phrase depends of operand types inside it. When a phrase is consisted of various data types, result type is set by defined casting rules. Rules for casting various data types in C language are oriented to higher data type. There are two ways of casting data types in C:

·automatic (implicit)

·given (explicit)

Implicit Casting (automatic transformation) works in a way that a variable (operand) of data type that is smaller in length (than data type of second variable) (operand), transforming internally to variable of data type with longer number length. It may sound mixed up, but here is an example:

I am corn-fused, I have been interested in learning a programming language for quite some time now but, never found the time to actually sit down and try and learn a language till 2 days ago. Before coming to this website I downloaded Code::Block ver. 1.0rc2 as an IDE to use. I have learned about loops and the famous(I guess) "Hello World". I thought I was doing ok but after reading the last couple chapters and then rereading them to try and understand everything you have put out...How do I say this tactfully?????? Do I really need to go back and learn this stuff completely inorder to Program?