Every problem might not have a solution right now, but don’t forget that but every solution was once a problem.
--Your friends at LectureNotes

Note for Object Oriented Programming Using Cpp - OOP by radha sharma

  • Object Oriented Programming Using Cpp - OOP
  • Note
  • Sikkim Manipal University - SMU
  • Uploaded 11 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

10/9/2018 TUTORIAL C Data Types: int, float, char and more  EXAMPLES C Programming Data Types In this tutorial, you will learn about data types and how to declare a variable in C programming. By using Programiz, you agree to use cookies as stated in our Privacy policy https://www.programiz.com/c-programming/c-data-types Continue 1/7

Text from page-2

10/9/2018 C Data Types: int, float, char and more In C programming, variables or memory locations should be declared before it can be TUTORIAL EXAMPLES used. Similarly, a function also needs to be declared before use.  Data types simply refers to the type and size of data associated with variables and functions. Data types in C 1. Fundamental Data Types Integer types Floating type Character type 2. Derived Data Types Arrays Pointers Structures Enumeration This tutorial will focus on fundamental data types. To learn about derived data types, visit the corresponding tutorial. int - Integer data types Integers are whole numbers that can have both positive and negative values but no decimal values. Example: 0, -5, 10 In C programming, keyword int is used for declaring integer variable. For example: int id; Here, id is a variable of type integer. You can declare multiple variable at once in C programming. For example: int id, age; The size of int is either 2 bytes(In older PC's) or 4 bytes. If you consider an integer having 32 size of 4 byte( equalyou to 32 bits), can take 2as distinctinstates as: -231 ,-231+1, ...,-2, -1, 0, 1, By using Programiz, agree to ituse cookies stated our Privacy policy Continue https://www.programiz.com/c-programming/c-data-types 2/7

Text from page-3

10/9/2018 C Data Types: int, float, char and more 2, ..., 231-2, 231-1.  If you try to store larger number than 231-1, i.e,+2147483647 and smaller TUTORIAL EXAMPLES  number than -231, i.e, -2147483648, program will not run correctly. Similarly, int of 2 bytes, it can take 216 distinct states from -215 to 215-1. oat - Floating types Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0 etc. You can declare a oating point variable in C by using either float or double keyword. For example: float accountBalance; double bookPrice; Here, both accountBalance and bookPrice are In C, oating type variables. oating values can be represented in exponential form as well. For example: float normalizationFactor = 22.442e2; Di erence between oat and double The size of float (single precision oat data type) is 4 bytes. And the size of double (double precision oat data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the precision of double is 14 digits. char - Character types Keyword char is used for declaring character type variables. For example: char test = 'h'; Here, test is a character variable. The value of test is 'h'. The size of character variable is 1 byte. C Quali ers By using agreeof to base use cookies as stated in our Privacy Quali ers Programiz, alters the you meaning data types to yield a new datapolicy type. https://www.programiz.com/c-programming/c-data-types Continue 3/7

Text from page-4

10/9/2018 C Data Types: int, float, char and more Size quali ers TUTORIAL EXAMPLES Size quali ers alters the size of a basic type. There are two size quali ers, long and  short . For example: long double i; The size of double   is 8 bytes. However, when long keyword is used, that variable becomes 10 bytes. Learn more about long keyword in C programming. There is another keyword  short   which can be used if you previously know the value of a variable will always be a small number. Sign quali ers Integers and oating point variables can hold both negative and positive values. However, if a variable needs to hold positive value only, unsigned data types are used. For example: // unsigned variables cannot hold negative value unsigned int positiveInteger; There is another quali er signed which can hold both negative and positive only. However, it is not necessary to de ne variable signed since a variable is signed by default. An integer variable of 4 bytes can hold data from -231 to 231-1. However, if the variable is de ned as unsigned, it can hold data from 0 to 232-1. It is important to note that, sign quali ers can be applied to int and char types only. Constant quali ers An identi er can be declared as a constant. To do so const keyword is used. const int cost = 20; The value of cost cannot be changed in the program. By using Programiz, you agree to use cookies as stated in our Privacy policy Volatile quali ers https://www.programiz.com/c-programming/c-data-types Continue 4/7

Lecture Notes