girlscript / winter-of-contributing

GirlScript Winter of Contributing is a three-month-long Open-Source Program organized by🧡GirlScript Foundation to create the world's largest multilingual content repository that will be available to everyone.
MIT License
880 stars 1.56k forks source link

C_CPP Type Casting #8189

Open dummy-co-der opened 3 years ago

dummy-co-der commented 3 years ago

Description


Type Casting - C Programming


What is type casting?

*Type casting refers to changing an variable of one data type into another. The compiler will automatically change one type of data into another if it makes sense. For instance, if you assign an integer value to a floating-point variable, the compiler will convert the int to a float. Casting allows us to make this type conversion explicit, or to force it when it wouldn’t normally happen.

*Type conversion in c can be classified into the following two types:

Implicit Type Conversion

An example of implicit conversion

#include <iostream>
using namespace std;

int main()
{
    int x = 10; // integer x
    char y = 'a'; // character c

    // y implicitly converted to int. ASCII
    // value of 'a' is 97
    x = x + y;

    // x is implicitly converted to float
    float z = x + 1.0;

    cout << "x = " << x << endl
         << "y = " << y << endl
         << "z = " << z << endl;

    return 0;
}

Output

x = 107
y = a
z = 108

Explict Type Conversion

An example of explicit conversion

#include <iostream>
using namespace std;

int main()
{
    double x = 1.2;

    // Explicit conversion from double to int
    int sum = (int)x + 1;

    cout << "Sum = " << sum;

    return 0;
}

Output

Sum = 2

Advantages of Type Conversion:

Domain

C/CPP

Type of Contribution

Documentation

Code of Conduct

github-actions[bot] commented 3 years ago

Hello @dummy-co-der,
Thank you for opening an issue. :octocat:
Note - Self-assigns by the original author will be prioritised by mentors manually
To get assigned to this particular issue please use /assign
Check this guide before contributing.

dummy-co-der commented 3 years ago

@vasu-1 Kindly review!

0xvashishth commented 3 years ago

Please make the pr

0xvashishth commented 3 years ago

issue can not be merged !

0xvashishth commented 3 years ago

you will have to make the changes in the repositories , and then make the pr for the respective issue !

0xvashishth commented 3 years ago

if you don't getting it then DM me in the discord

dummy-co-der commented 3 years ago

@vasu-1 Kindly review #8308 PR

srockstech commented 2 years ago

Can I work on this issue?

srockstech commented 2 years ago

@vasu-1

0xvashishth commented 2 years ago

@vasu-1

already working @dummy-co-der