Home | | Object Oriented Programming | Native Types - C++

Chapter: Object Oriented Programming(OOP) : Overview

Native Types - C++

Native C++ Types: Bottom Line

NATIVE TYPES

  bool

 

  char, wchar_t

o   modified with signed or unsigned


int

modified with signed or unsigned o can be modified with short or long o int can be dropped! long num;

o   can be modified with const or volatile

 

Native C++ Types: Bottom Line

 

float 

double  long double

bool

char

int     unsigned long

float double

pitfalls

 

Type Size

 

Language standard does not define the size of native types sizeof(type) operator

 

limits.h and float.h

 

Defines the largest and smallest type values include <limits>

 

o   numeric_limits<type>::max()

 

1. Implicit conversions (coercion)

 

Occur in mixed expressions Widening conversions:

 

int < unsigned < long < unsigned long < float < double < long double Widening safe, narrowing unsafe.

 

But: narrowing conversions allowed with assignments

 

2. Enumeration Types

Named integer constants

 

enum Animal {Cat, Dog, Horse = 5}; Tag name, enumerators must be unique Implicit conversion to integer

int i = Dog; // assigns 1 to i

 

 

Explicit cast from integer

 

y Animal anim = static_cast<Animal>i; C++ trick:

 

enum {SIZE = 100}; replaces #define SIZE 100


NATIVE C++ STATEMENTS

 

Expressions

§    expression ;

 

§    compound

 

Conditional

 

o if/if-else Iteration

 

o while o for

 

o do (not as common as iteration) switch/case

 

Formatting conventions Assignment Statements

         Syntax template

Variable = Expression ;

         Operation

 

– The expression on the right hand side is evaluated and assigned to the memory location named by the variable on the left hand side.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Overview : Native Types - C++ |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.