Type Casting, Command Line Arguments and Defining Constants.
Type Casting
what is Type casting ?
- Type casting in C language refers to the process of converting a value from one data type to another.
- This is necessary when you want to perform operations or assignments involving variables of different data types.
- There are two types of type casting in C
1) Implicit Type Casting :-
- Automatic conversion performed by the compiler without the programmer's intervention.
- Generally, occurs when a lower-ranked (smaller size) data type is promoted to a higher-ranked (larger size) data type to avoid loss of data.
- For example, when assigning an integer to a floating-point variable, the integer is implicitly cast to a float.
2) Explicit Type Casting:-
- Also known as manual type casting or casting operator.
- Involves the programmer explicitly specifying the conversion.
- Syntax:- (type) expression
- Useful when converting from a higher-ranked data type to a lower-ranked data type, as it may result in data loss.
Command Line Arguments
- It is possible to pass some values from the command line to your C programs when they are executed.
- These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard coding those values inside the code.
- The command line arguments are handled using main() function arguments where argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program.
Defining Constants
There are two ways to define constant in C programming.
Example :-
Write a program to read the radius of a circle and print out the perimeter of it on the screen.
• Method 01 - Using the const keyword.
• Method 02 - Using the #define directive.
Math Functions
- The math.h header defines various mathematical functions.
- All the functions available in this library take double as an argument and return double as the result.
example -
Comments
Post a Comment