Abstract
Uninitialised variables
Uninitialised variables in C contain unknown values, unlike Java which sets for uninitialised Primitive Datatype!
How to find the spaces used by a datatype?
sizeof(int)returns the size ofintin the current machine.
Importance of explicit datatype
C uses the data type to determine the underlying instruction to be generated. Different instructions are used to handle floating-point numbers and integers.
What is char in C?
Char is basically a 8-bit integer, but usually used to hold a character using ascii table.
Everything in C is an number!
No boolean type in ANSI C!
0is used to representfalse, any other value is used to representtrue.
int size
intwas designed to match the word size of the machine, so it was 16 bits on 16-bit machines, 32 bits on 32-bit machines, and so on.
C Mixed-type Arithmetic Operation
10/4.0will give us float2.0, but if weint p = 10/4.0,pwill have a value of2which converts from float2.0to int210 / 4.0involves a float operand, so the result is the floating-point value2.5. If you assign this to anintvariable likeint p = 10 / 4.0, the fractional part is truncated, andpwill store the integer value2.
Type Casting in C
float p = (float) 6 / 4will result inp = 1.5. The(float)explicitly converts the integer6to a float before the division occurs. This ensures that floating-point division is performed, yielding a floating-point resultfloat p = (float) (6 / 4)will result inp = 1.0. The expression within the parentheses(6 / 4)is evaluated first. Since both operands are integers, integer division is performed, resulting in1. This integer value is then converted to a float using the(float)cast.
