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 ofint
in 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!
0
is used to representfalse
, any other value is used to representtrue
.
C Mixed-type Arithmetic Operation
10/4.0
will give us float2.0
, but if weint p = 10/4.0
,p
will have a value of2
which converts from float2.0
to int2
10 / 4.0
involves a float operand, so the result is the floating-point value2.5
. If you assign this to anint
variable likeint p = 10 / 4.0
, the fractional part is truncated, andp
will store the integer value2
.
Type Casting in C
float p = (float) 6 / 4
will result inp = 1.5
. The(float)
explicitly converts the integer6
to 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.