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 of int 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 represent false, any other value is used to represent true.

C Mixed-type Arithmetic Operation


  1. 10/4.0 will give us float 2.0, but if we int p = 10/4.0, p will have a value of 2 which converts from float 2.0 to int 2
  2. 10 / 4.0 involves a float operand, so the result is the floating-point value 2.5. If you assign this to an int variable like int p = 10 / 4.0, the fractional part is truncated, and p will store the integer value 2.

Type Casting in C

  1. float p = (float) 6 / 4 will result in p = 1.5. The (float) explicitly converts the integer 6 to a float before the division occurs. This ensures that floating-point division is performed, yielding a floating-point result
  2. float p = (float) (6 / 4) will result in p = 1.0. The expression within the parentheses (6 / 4) is evaluated first. Since both operands are integers, integer division is performed, resulting in 1. This integer value is then converted to a float using the (float) cast.