Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Type Casting

    float a = 10.3;
    int b;
    char c = 's'; //115 in ASCII

    //USING IMPLICIT TYPECASTING
    b = a / 2; //where the value of 'a' turned into int value 
    cout << b << endl;
    cout << b + c << endl;

    //USING EXPLICIT TYPECASTING
    cout << (int) a + 8 << endl;
Comment

c++ cast to type of variable

x = static_cast<decltype(x)>(y);
Comment

type casting in cpp

int main()
{
	int a=20 , b= 25 , c= 19;
  	int sum = a + b + c;
  	float ave = (float) sum / 3;  //this is called type casting (float) sum 
  	cout<<"Average is : "<<ave<<endl;
  	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: what is thread in c++ 
Cpp :: palindrome checker in c++ 
Cpp :: c++ function default argument 
Cpp :: C++ break with for loop 
Cpp :: c++ logger class example 
Cpp :: what is a template in c++ 
Cpp :: Reverse Level Order Traversal cpp 
Cpp :: log in c++ 
Cpp :: c++ ternary operator 
Cpp :: bee 1002 solution 
Cpp :: how to compile opencv c++ in ubuntu 
Cpp :: str remove char c++ 
Cpp :: how to find min of two numbers in c++ 
Cpp :: odd numbers 1 to 100 
Cpp :: c++ do every 1 minutes 
Cpp :: doubly linked list in cpp 
Cpp :: c++ initialize a vector 
Cpp :: what is meant by pragma once in c++ 
Cpp :: how to know the number of a certain substring in a string in c++ 
Cpp :: c++ multiple inheritance 
Cpp :: Give an algorithm for finding the ith-to-last node in a singly linked list in which the last node is indicated by a null next reference. 
Cpp :: c for loop decrement 
Cpp :: double array size c++ 
Cpp :: c++ print 
Cpp :: pass map as reference c++ 
Cpp :: how to take full sentence in c++ 
Cpp :: c++ program to print odd numbers using loop 
Cpp :: makefile for single cpp file 
Cpp :: c++ check that const char* has suffix 
Cpp :: c++ custom hash 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =